(*--- Write Your Class or Structure -------*)
TMyObject = class(TObject)
Code: string;
Name: string;
remark: string;
end;
(*--- Write List Class for your Class or Structure ---*)
TMyObjectList = class(TList)
function GetItemAt(i: Integer): TMyObject ;
public
destructor Destroy; override;
function Add(f: TMyObject ): Integer;
property ItemAt[i: Integer]: TMyObject read GetItemAt;
end;
var
MyList: TMyObjectList;
Implementation
function TMyObjectList .ItemAt(i: Integer): TMyObject ;
begin
result := TMyObject(Items[i]);
end;
function TMyObjectList .Add(f: TMyObject ): Integer;
begin
result := inherited add(f);
end;
destructor TMyObjectList .Destroy; override
var
anObj: TMyObject;
begin
while Count > 0 do begin
anObj := ItemAt[0];
delete(0);
anObj.free;
end;
inherited;
end;
procedure BuildMyList(aDataSet: TDataSet);
var
anObj: TMyObject;
begin
if Assigned(MyList) then MyList.Free;
MyList := TMyObjectList.Create;
while not aDataSet.eof do begin
anObj := TMyObject.create;
anObj.Code := aDataSet.fieldByName('Code').AsString;
anObj.Name := aDataSet.fieldByName('Name).AsString;
anObj.Remark := aDataSet.fieldByName('Remark').AsString;
MyList.add(anObj)
end;
end;
Type
(*--- Write Your Class or Structure -------*)
TMyObject = class(TObject)
Code: string;
Name: string;
remark: string;
end;
(*--- Write List Class for your Class or Structure ---*)
TMyObjectList = class(TList)
function GetItemAt(i: Integer): TMyObject ;
public
destructor Destroy; override;
function Add(f: TMyObject ): Integer;
property ItemAt[i: Integer]: TMyObject read GetItemAt;
end;
var
MyList: TMyObjectList;
Implementation
function TMyObjectList .ItemAt(i: Integer): TMyObject ;
begin
result := TMyObject(Items[i]);
end;
function TMyObjectList .Add(f: TMyObject ): Integer;
begin
result := inherited add(f);
end;
destructor TMyObjectList .Destroy; override
var
anObj: TMyObject;
begin
while Count > 0 do begin
anObj := ItemAt[0];
delete(0);
anObj.free;
end;
inherited;
end;
procedure BuildMyList(aDataSet: TDataSet);
var
anObj: TMyObject;
begin
if Assigned(MyList) then MyList.Free;
MyList := TMyObjectList.Create;
while not aDataSet.eof do begin
anObj := TMyObject.create;
anObj.Code := aDataSet.fieldByName('Code').AsString;
anObj.Name := aDataSet.fieldByName('Name).AsString;
anObj.Remark := aDataSet.fieldByName('Remark').AsString;
MyList.add(anObj)
end;
end;
도움이 되길 바랍니다.
이준해