<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">It's work at my computer <br>I used WinXP SP3 and Lazarus 0.9.26 beta<br>This my code... do you miss something ?<br><br>function TSLFunctn(myTSL: TStringList):integer;<br>var i: integer;<br>begin<br> Result:=0;<br> for i:=0 to myTSL.Count-1 do //<-----------fails here<br> begin<br> Result+=strtoint(myTSL.Strings[i]);<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> a:TStringList;<br>begin<br> a:=TStringList.Create;<br> a.Add('1');<br> a.Add('2');<br> ShowMessage(inttostr(TSLFunctn(a)));<br>end; <br><br><br>=============INTOSOFT============<br>
ALEXIO CHAOS<br>
Darmawan_Sugiarto@yahoo.com <br>
Yahoo Messager<br>
=================================<br><br>--- On <b>Tue, 1/20/09, Luca Olivetti <i><luca@wetron.es></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Luca Olivetti <luca@wetron.es><br>Subject: Re: [Lazarus] Possible bug passing a TStringList to a function.<br>To: "General mailing list" <lazarus@lazarus.freepascal.org><br>Date: Tuesday, January 20, 2009, 12:02 AM<br><br><div class="plainMail">En/na Dave Coventry ha escrit:<br>> Hi,<br>> <br>> If I pass a TStringList to a function:<br>> <br>> function TSLFunctn(myTSL: TSltringList):integer;<br>> var i: integer;<br>> begin<br>> Result:=0;<br>> for i:=0 to myTSL.Count-1 do //<-----------fails here<br>> begin<br>> Result+=strtoint(myTSL.Strings[i]);<br>> end;<br>> end;<br>> <br>> The function fails when I try to assign quantify myTSL.Count.<br><br>works here (without the
typo)<br><br>> <br>> However, this works:<br>> <br>> function TSLFunctn(myTSL: TSltringList):integer;<br>> var i: integer;<br>> internalTSL: TStringList;<br>> begin<br>> internalTSL:= TStringList.Create;<br>> internalTSL:=myTSL;<br><br>this is:<br><br>1) a memory leak (you create a stringlist then ignore it, losing the <br>pointer)<br>2) exactly the same as before (a stringlist variable, as any other <br>class, is actually a pointer, so if you use := both are pointing at the <br>same object, if you want to make a copy you have to use assign, provided <br>that the class implements it correctly)<br><br><br>> Result:=0;<br>> for i:=0 to internalTSL.Count-1 do //<-----------works<br>> begin<br>> Result+=strtoint(internalTSL.Strings[i]);<br>> end;<br>> internalTSL.Free;<br><br>and here you are freeing the original stringlist, not the locally <br>created one.<br><br><br>Bye<br>-- <br>Luca Olivetti<br>Wetron
Automatización S.A. <a href="http://www.wetron.es/" target="_blank">http://www.wetron.es/</a><br>Tel. +34 93 5883004 Fax +34 93 5883007<br>_______________________________________________<br>Lazarus mailing list<br><a ymailto="mailto:Lazarus@lazarus.freepascal.org" href="/mc/compose?to=Lazarus@lazarus.freepascal.org">Lazarus@lazarus.freepascal.org</a><br><a href="http://www.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://www.lazarus.freepascal.org/mailman/listinfo/lazarus</a><br></div></blockquote></td></tr></table><br>