Hello

What are the do and donn't when passing Lists from one procedure to another.

I do have three different procedures:

ProcedureOne;
var
  LStringlist : TStringlist;
begin
   LStringlist : TStringlist.create;

  LStringlist.add.... 

   procedureTwo(Lstringlist);

   if LStringlist <> nil then
   LStringlist.free;
end;

procedureTwo(AStringList : TStringlist = nil);
var
  lStringlist : TStringlist;
begin
   if AStringlist = nil then
     lStringlist := TStringlist.create 
  else
     lStringlist = AStringlist;

  //do something

  LStringlist.free;
end;

ProcedureThree
begin
   proceduretwo;
end

I had an AV problem when freeeing the LStringlist in procedureOne. This was 
because it's already been freed in ProcedureTwo. 
However where and when should the lStringlist in each procedure be freed?  
( I thought that after lStringlist = AStringlist in procedureTwo and the 
LStringlist.free the original LStringlist in ProcedureOne would also have been 
freed; Debugging shows that this is not true. )

I hope your answers would help me understand how and when a parameter may and 
should be freed.

Regards

Andries


      

[Non-text portions of this message have been removed]

Reply via email to