[fpc-pascal] Problem with objects
    Jonas Maebe 
    jonas.maebe at elis.ugent.be
       
    Wed Dec 23 18:24:36 CET 2015
    
    
  
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;
> 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?
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.
Dennis Poon wrote:
> I think for both Record or Object, you need to initialize any dynamic
> array or strings fields before using them.
That is incorrect, the compiler takes care of it (or is supposed to, 
anyway).
Jonas
    
    
More information about the fpc-pascal
mailing list