...
1. ldsandon, SetLength , . , 2 , , .
, , StringOfChar('A',5), SetLength ( )
2. , . :
procedure someproc
var Obj1, obj2 : TObject;
begin
[...]
obj2 := Obj1;
Obj1 := nil;
//I want Obj2 to be also nil here since obj1 is nil...
end;
, PStr , , , .
-:
procedure TForm1.FormCreate(Sender: TObject);
var
Str: string;
PStr: PChar absolute Str;
begin
PStr, Str.
Secondly:
procedure TForm1.FormCreate(Sender: TObject);
var
Str: string;
function PStr: PChar
begin
Result := PChar(Str);
end
begin
But it's always best to just use "PChar (Str)", where you need to access your string as Pchar.
Also, do not fake this if you are writing to a string through the PChar variable, you must make sure that the string has a reference count of 1 first (by calling UniqueString or SetLength).
source
share