Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-07

Freepascal and good usage of TStringList

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jean-Marc Chourot

Dear All,
Could any one help me debug the little piece of code thereafter ? I get a SIGSEGV.. and I don't know why (OK.. i am not that good). Thanks for your help.

JM
*****************************
Program TestStringList;

Uses
 CLasses;
 var TheStringList:TStringList;
 Procedure PopulateList(var Mylist :TstringList);
 var StringlistLocal:TStringList;
 begin
  StringlistLocal.create;
  StringlistLocal.add('This is a sample Text');
  StringlistLocal.add('This is a second sample Text');
  StringlistLocal.add('This is a third sample Text');
 Mylist.Assign( StringlistLocal );
   StringlistLocal.destroy;
 end;
 Function CleanList(  EnterList:TstringList ;   var Outlist
:TstringList):boolean;
var i: integer;
 begin
   For i:=0 to EnterList.Count-1 do Outlist.add( EnterList[i]);
 end;
 Procedure CallList( Var CleanedList:Tstringlist);
 var List0,list1 : Tstringlist;
 Foo: boolean;
 begin
 List0.create;
 //  Here I get a SIGSEGV
 List1.create;
 Populatelist(list0);
 foo := CleanList(List0,list1);
 CleanedList.assign(List1);
 List0.destroy;
 List1.destroy;
 end;
 begin
  TheStringList.create;
  CallList(TheStringList);
 end.

*************************

Reply by email

Martin Smat
to Jean-Marc Chourot
Jean-Marc Chourot wrote 43 lines
Dear All, Could any one help me debug the little piece of code thereafter ? I get a SIGSEGV.. and I don't know why (OK.. i am not that good). Thanks for your help. JM ***************************** Program TestStringList; Uses CLasses; var TheStringList:TStringList; Procedure PopulateList(var Mylist :TstringList); var StringlistLocal:TStringList; begin StringlistLocal.create; StringlistLocal.add('This is a sample Text'); StringlistLocal.add('This is a second sample Text'); StringlistLocal.add('This is a third sample Text'); Mylist.Assign( StringlistLocal ); StringlistLocal.destroy; end; Function CleanList( EnterList:TstringList ; var Outlist :TstringList):boolean; var i: integer; begin For i:=0 to EnterList.Count-1 do Outlist.add( EnterList[i]); end; Procedure CallList( Var CleanedList:Tstringlist); var List0,list1 : Tstringlist; Foo: boolean; begin List0.create; // Here I get a SIGSEGV
Use List0 := TStringList.Create;
List1.create;
List1 := TStringList.Create;

Martin.

Show quoted text 22 lines
Populatelist(list0); foo := CleanList(List0,list1); CleanedList.assign(List1); List0.destroy; List1.destroy; end; begin TheStringList.create; CallList(TheStringList); end. ************************* _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Mariano
to Jean-Marc Chourot: Could any one help me debug the little piece of code thereafter ? I get a SIGSEGV.. and I…

Well... :-P i'm not good too... but i think that the problems is:

List0 and List1 are pointers to an TStringList Object... so, the right sentence must be:

List0 := TStringList.Create;
List1 := TStringList.create;

intead

List0.create;
List1.create;

".Create" are a class method that give a pointer to the created object...

And the same for free them:

List0.Free;
List1.Free;

intead

List0.Destroy;
List1.Destroy;

:-)

Other issues:

* The Result of the function "CleanList" is never assigned!
* As Parameter... change:
procedure My_Proc(var SL :TstringList);
to
procedure My_Proc(Const SL :TstringList);

:-) hope that this can help you! :-P

Reply by email

Jean-Marc Chourot
to Mariano

dear Mariano,
OH.. many thanks... How stupid I was !
I feel better now !
JM

Earlier message 45 lines
-----Message d'origine----- De : la part de Mariano Envoyé : lundi 25 juillet 2005 20:11 À : 'FPC-Pascal users discussions' Objet : RE: [fpc-pascal] Freepascal and good usage of TStringList Well... :-P i'm not good too... but i think that the problems is: List0 and List1 are pointers to an TStringList Object... so, the right sentence must be: List0 := TStringList.Create; List1 := TStringList.create; intead List0.create; List1.create; ".Create" are a class method that give a pointer to the created object... And the same for free them: List0.Free; List1.Free; intead List0.Destroy; List1.Destroy; :-) Other issues: * The Result of the function "CleanList" is never assigned! * As Parameter... change: procedure My_Proc(var SL :TstringList); to procedure My_Proc(Const SL :TstringList); :-) hope that this can help you! :-P

Reply by email