Currently I am adding object by creating it like:
type
TRecord = class
private
str: string;
num: Integer;
public
constructor Create;
end;
...
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
rec: TRecord;
Alist: TStringList;
begin
Alist := TStringList.create;
Alist.Clear;
for i := 0 to 9 do
begin
rec := Trecord.Create; //create instance of class
rec.str := 'rec' + IntToStr(i);
rec.num := i * 2;
Alist.AddObject(IntToStr(i), rec);
end;
end;
Is this method correct or inefficient ? Or Can I directly add object not by creating it like using record?
type
PRec = ^TRec;
TRec = record
str: string;
num: Integer;
end;
...
var
rec: TRec;
...
for i := 0 to 9 do
begin
//how to write here to have a new record,
//can i directly Create record in delphi 7 ?
rec.str := 'rec' + IntToStr(i);
rec.num := i*2;
Alist.AddObject(IntToStr(i), ???); // how to write here?
end;
Or other fast and simple way?
I am using Delphi 7.
Thanks in advance.
TObject
. – Barnwell