Dynamic arrays of record/object
- From: sakkieLFS@xxxxxxxxx
- Date: Wed, 12 Mar 2008 11:46:46 -0700 (PDT)
Hi Al,
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;
procedure AddSection(DataHeader: string; Data: string);
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TXMLSectionData }
procedure TXMLSectionData.AddSection(DataHeader, Data: string);
begin
SetLength(FSectionData,FCount+1);
FSectionData[FCount].DataHeader:= DataHeader;
FSectionData[FCount].Data:= Data;
Inc(FCount);
end;
constructor TXMLSectionData.Create;
begin
inherited;
FCount:= 0;
SetLength(FSectionData,FCount);
end;
destructor TXMLSectionData.Destroy;
begin
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
var Data: TXMLSectionData;
begin
Data.Create;
Data.AddSection('Header1','test data');
end;
function TXMLSectionData.GetCount: integer;
begin
Result := FCount;
end;
end.
.
- Follow-Ups:
- Re: Dynamic arrays of record/object
- From: alanglloyd@xxxxxxx
- Re: Dynamic arrays of record/object
- From: Rob Kennedy
- Re: Dynamic arrays of record/object
- From: Hans-Peter Diettrich
- Re: Dynamic arrays of record/object
- Prev by Date: Re: Delphi is evil
- Next by Date: Re: Dynamic arrays of record/object
- Previous by thread: Re: Delphi is evil
- Next by thread: Re: Dynamic arrays of record/object
- Index(es):