[fpc-pascal] Problem with objects

Santiago A. svaa at ciberpiula.net
Wed Dec 23 12:40:11 CET 2015


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;
>>
>> TDerivedArrayString=object(TSimpleArrayString)
>>      other_field:integer;
>> end;
>>
>> procedure TestSimple;
>> var
>>   A:TSimpleArrayString;
>> begin
>>    setLength(A.List,0);
>> end;
>>
>> procedure TestDerived;
>> var
>>   A:TDerivedArrayString;
>> begin
>>    setLength(A.List,0);
>> end;
>>
>>
>> TestSimple; // Works Fine,
>> TestDerived; // rises an exception SIGSEGV on setLength
>>
>> What am I doing wrong?
>>
> 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 reference count of A.List
> (which is not nil) and raisesSIGSEGV.
>
> Dennis
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
It's an object, not a class inherited from Tobject, so it hasn't create
constructor.

-- 
Saludos

Santi
svaa at ciberpiula.net




More information about the fpc-pascal mailing list