Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Jonas Maebe
Santiago A. wrote: In TDerivedArrayString I need to manually set the length of the list to zero. If I don't, the memory is not freed, but in TSimpleArrayString it frees memory. Is it also a known bug of 2.6.4? Yes, it was fixed at the same time IIRC. Jonas ___

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Santiago A.
El 23/12/2015 a las 18:24, Jonas Maebe escribió: > Santiago Amposta wrote: > > > This is a bug in FPC 2.6.4 (it did not initialise managed fields of > parent objects for child objects that do not declare extra managed > fields). It is fixed in FPC 3.0. > I have used constructors as a workaround no

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Jonas Maebe
Santiago Amposta wrote: I use fpc 2.6.4 and I have a problem of memory leaks, strange errors, etc. Finally I have tracked it to this: TSimpleArrayString=object List:array of String; end; TDerivedArrayString=object(TSimpleArrayString) other_field:integer; end; procedure TestSimple; v

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Lukasz Sokol
On 23/12/15 16:06, Santiago A. wrote: > El 23/12/2015 a las 16:24, Lukasz Sokol escribió: >> On 23/12/15 09:37, Santiago Amposta wrote: >> I might be wrong... but I just tried: >> >> ... > > What's the conclusion? As far as I see, there is some kind of bug. > > There is no reason for getting

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Dennis Poon
I think for both Record or Object, you need to initialize any dynamic array or strings fields before using them. If you don't use any constructor , you need to initialize the fields yourself. Being an object, just gives you the added automatic zeroing of its content. Advanced Record does not

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Santiago A.
El 23/12/2015 a las 16:49, Dennis Poon escribió: > > > Even if it is an object, you can still define a constructor. > A constructor should initialize the memory area of the object to 0, > even if you don't explicitly assign List := nil; > It is safer to call this constructor before you handle the L

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Santiago A.
El 23/12/2015 a las 16:24, Lukasz Sokol escribió: > On 23/12/15 09:37, Santiago Amposta wrote: > I might be wrong... but I just tried: > > ... What's the conclusion? As far as I see, there is some kind of bug. There is no reason for getting different results depending on how you execute two

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Dennis Poon
Santiago A. wrote: El 23/12/2015 a las 12:13, Dennis Poon escribió: Did you call A.Create before calling TestDerived? Maybe A.List was not initialized (which is done in constructor Create) and contains an invalid pointer (to dynamic array of string). When you call SetLength, it decrements the

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Lukasz Sokol
On 23/12/15 09:37, Santiago Amposta wrote: > Hello: > I use fpc 2.6.4 and I have a problem of memory leaks, strange errors, > etc. Finally I have tracked it to this: > > TSimpleArrayString=object > List:array of String; > end; > > TDerivedArrayString=object(TSimpleArrayString) > other_fie

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Howard Page-Clark
On 23/12/2015 11:40, Santiago A. wrote: It's an object, not a class inherited from Tobject, so it hasn't create constructor. Try this: program simpleObjConsole; type { TSimpleArrayString } TSimpleArrayString=object public List:array of String; constructor Init; destructo

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Santiago A.
El 23/12/2015 a las 12:13, Dennis Poon escribió: > > > Santiago Amposta wrote: >> Hello: >> I use fpc 2.6.4 and I have a problem of memory leaks, strange errors, >> etc. Finally I have tracked it to this: >> >> TSimpleArrayString=object >> List:array of String; >> end; >> >> TDerivedArrayStrin

Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Dennis Poon
Santiago Amposta wrote: Hello: I use fpc 2.6.4 and I have a problem of memory leaks, strange errors, etc. Finally I have tracked it to this: TSimpleArrayString=object List:array of String; end; TDerivedArrayString=object(TSimpleArrayString) other_field:integer; end; procedure TestS