我试图找到最有效的方法, 从 Delphi/Lazarus FreePascal 收藏中更新网格( StringGrid 或 KGrid ) 。
我的一个收藏品如下:
{ TEntretien }
TEntretien = class(TCollectionItem)
private
{ private declarations }
FPrenom: string;
FSexe: string;
FSigneDistinctif: string;
FPays: string;
FTotale: integer;
FColumns: integer;
public
{ public declarations }
published
{ published declarations }
property Prenom: string read FPrenom write FPrenom;
property Sexe: string read FSexe write FSexe;
property SigneDistinctif: string read FSigneDistinctif write FSigneDistinctif;
property Pays: string read FPays write FPays;
property Totale: integer read FTotale write FTotale;
end;
{ TEntretiens }
TEntretiens = class(TCollection)
private
{ private declarations }
function GetItem(AIndex: integer): TEntretien;
public
{ public declarations }
constructor Create;
function Add: TEntretien;
property Items[AIndex: integer]: TEntretien read GetItem; default;
end;
我有以下代码片段,用来更新我的网格之一:
// Fill the grid with the results of the query
for intGridRow := 0 to intNumberOfRows - 1 do
begin
for intGridCol := 0 to intNumberOfColumns - 1 do
begin
// Write the rest of the retrieved data into the grid proper USE RTTI HERE??
if intGridCol = 0 then
kgGridName.Cells[intGridCol + kgGridName.FixedCols, intGridRow + kgGridName.FixedRows] :=
AEntretiens[intGridRow].Prenom
else if intGridCol = 1 then
kgGridName.Cells[intGridCol + kgGridName.FixedCols, intGridRow + kgGridName.FixedRows] :=
AEntretiens[intGridRow].Sexe
else if intGridCol = 2 then
kgGridName.Cells[intGridCol + kgGridName.FixedCols, intGridRow + kgGridName.FixedRows] :=
AEntretiens[intGridRow].SigneDistinctif
else if intGridCol = 3 then
kgGridName.Cells[intGridCol + kgGridName.FixedCols, intGridRow + kgGridName.FixedRows] :=
AEntretiens[intGridRow].Pays
else if intGridCol = 4 then
kgGridName.Cells[intGridCol + kgGridName.FixedCols, intGridRow + kgGridName.FixedRows] := IntToStr(AEntretiens[intGridRow].Totale)
end;
end;
这对少量字段/财产的收藏来说是罚款,但我也有多达40个字段的收藏,所以我上面使用的方法太麻烦了。
是否有更有效的方法这样做?有人建议RTTI,但我不知道如何使用它。
非常感谢
达尼尔