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를 제안했지만 사용 방법을 모른다.
고마워,
JDaniel 여기
소유자 도면 사용에 대해 생각해 보셨습니까? 그렇게하면 그리드에서 실제로 볼 수있는 콜렉션 부분에만 액세스해야합니다. 뻔뻔한 플러그 : TdzVirtualStringGrid [dzlib] (http://sourceforge.net/p/dzlib/code/125/tree/) – dummzeuch