Re: Dynamic arrays of record/object



On Mar 13, 12:08 am, Hans-Peter Diettrich <DrDiettri...@xxxxxxx>
wrote:
sakkie...@xxxxxxxxx wrote:
I ready to pull out my hair on the creation of dynamic arrays of a
record or object. For some reason I'm having problems setting the
lenght of the array and assigning values to the elements of the array
(which is a record). I have included source code. Please help!

type

  TSectionData = record
    DataHeader: string;
    Data: string;
  end;

  TXMLSectionData = class(TObject)

  private
    FCount: Integer;
    FSectionData: array of TSectionData;
    function GetCount: integer;
  public

    constructor Create;
    destructor Destroy; override;

    property Count: integer read GetCount write FCount;

Properties typically are *write* protected, i.e.:
      property Count: integer read FCount write SetCount;



    procedure AddSection(DataHeader: string; Data: string);

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

DoDi- Hide quoted text -

- Show quoted text -

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


Quantcast