Delphi
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists Delphi

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 4th, 2008, 06:32 AM
Andries Bos
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
explaination on assings and free parameters

Hello

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

I do have three different procedures:

P;
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 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 P 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 With Quote
  #2  
Old June 4th, 2008, 06:32 AM
Martin Wynne
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
explaination on assings and free parameters

Hi,

procedureTwo(AStringList : TStringlist = nil);

Your code creates a new local StringList in procedureTwo.

Use a var parameter:

procedureTwo(var AStringList : TStringlist);

to pass the existing StringList, which is what I think you want.

Martin.

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists Delphi > explaination on assings and free parameters


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway