> 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.
                                          
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to