> How do I write a library function which returns a TStringList object?
> To be used like:
> function MyFunction(a, b, c: String): TStringlist;
> begin
> ...
> StringList.AddStrings(MyFunction(a, b, c));
> ...

You must not write it to be used like that... A stringlist would be returned,
and the reference discarded without freeing the associated object...

You can do 2 things

1.
function MyFunction(const a,b,c :String):TStrings;
begin
   Result := TStringLIst.Create;
   with Result do begin
     BeginUpdate;
     Clear;
     Add(a);
     Add(b);
     Add(c);
     EndUpdate;
   end;
end;

used with
var
  SL :Tstrings;
begin
   SL := MyFunction('1','2','3');
   StringLIst.AddStrings(SL);
   SL.Free;
end;

2.
function MyFunction(const a,b,c :String; SL :Tstrings):TStrings;
begin
   Result := SL;
   with Result do begin
     BeginUpdate;
     Clear;
     Add(a);
     Add(b);
     Add(c);
     EndUpdate;
   end;
end;

var
  SL :Tstringlist;
begin
   SL := TStringlist.Create;
   Stringlist.AddStrings(MyFunction('1','2','3',SL));
   SL.Free;
end;

Either way you must free it...

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to