Freepascal and good usage of TStringList

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Freepascal and good usage of TStringList

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.

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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal and good usage of TStringList

Martin Smat
Jean-Marc Chourot wrote:

>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.

> Populatelist(list0);
> foo := CleanList(List0,list1);
> CleanedList.assign(List1);
> List0.destroy;
> List1.destroy;
> end;
>
>
> begin
>  TheStringList.create;
>  CallList(TheStringList);
> end.
>
>*************************
>
>
>_______________________________________________
>fpc-pascal maillist  -  [hidden email]
>http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>  
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: Freepascal and good usage of TStringList

Mariano-3
In reply to this post by Jean-Marc Chourot
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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: Freepascal and good usage of TStringList

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

-----Message d'origine-----
De : [hidden email]
[mailto:[hidden email]]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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal