Re: Dynamic arrays of record/object



sakkieLFS@xxxxxxxxx wrote:

procedure TForm1.Button1Click(Sender: TObject);
var Data: TXMLSectionData;
begin
Data.Create;
Data.AddSection('Header1','test data');

end;

The object in the local variable will be lost (memory leak) on exit from
the method :-(

Move the "var Data..." line into the form class, the "Data.Create" into
the form constructor, and add Data.Free to the form destructor.

If I declare this variable anywhere else besides local in the
eventhandler, it fails????

The statement should read:
Data := TXMLSectionData.Create;
regardless of where the Data variable resides.

DoDi
.


Quantcast