[fpc-pascal] Library.StringFunction() : PChar => NO

Fred van Stappen fiens at hotmail.com
Sat Mar 15 00:07:47 CET 2014


> Note: if your MyString is valid through the complete lifetime it could 
> be used you can also use "Result := PChar(MyString);"

Hum, to be sure that i understand...

type
  TStringClass = class(TObject)
    Name: AnsiString;  //// does not change
    SomeText: AnsiString; ///// may change..
  end;

var
AStringClass : TStringClass;

....

function GetName: PChar;  cdecl ;
begin

result := PChar(AStringClass.Name);
end;

function GetSomeText: PChar;  cdecl ;
var
   MyString: AnsiString ;
begin

 MyString := AStringClass.SomeText ;
   Result := GetMem(Length(MyString) + 1);

   Move(@MyString[1], Result, Length(MyString));

   Result[Length(MyString)] := 0;

end;


Is it OK ?

Thanks.
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140315/d02a03af/attachment.html>


More information about the fpc-pascal mailing list