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

Fred van Stappen fiens at hotmail.com
Fri Mar 14 14:47:24 CET 2014


Hello great fpc people.

It is about functions dealing with string  inside a library...

If i use that kind of function inside the library :

>> InLibStringFunction() : PChar ;

It will be the memory manager of the library who deals with the PChar result.
So difficult for the main application to manage the memory used by PChar.

Some good guru show me the way how to deal with string result inside a library :

>> In library :
MyStrTest(inStr:Pchar; outStr:pChar; size:integer):integer; cdecl;  
var 
  MyRealResult :string;
begin
 MyRealResult :=   inStr + ' added by function ';
  Result := length(myRealResult);
if size >= result then move(OutStr[0], MyRealResult[1], result);
end;

>> And in main program :
 function  testLib(InputText : string) : string ;
var
 MyStrOut : string;
  MyLen : integer;
begin
   MyLen := MyStrTest( @InputText[1], at MyStrOut[1], 0);
   SetLEngth(MyStrOut, mylen+1); 
   FillChar(MyStrOut[1], MyLen+1,0);
   MyStrTest(@InputText[1], @MyStrOut[1], 0);
 result := MyStrOut ;
end;

I have test it but, sadly, MyStrOut is always a empty string... ;-(

Could somebody give a working code ?
Or maybe, does it exist a better way to do it ?

Many thanks.

Fred.


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140314/733ae577/attachment.html>


More information about the fpc-pascal mailing list