당신 말이 맞습니다. 열의 위치를 추적해야합니다. 어쩌면 별도의 구조 또는 TCustomGrid에서 파생 된 자손 객체 일 수 있습니다.
나는 열의 크기, 포함하는 데이터 형식, 정렬 순서, 서식 옵션 및 그리드에서의 위치를 저장하는 컨테이너 개체를 유지합니다. 그리고 컨테이너를 참조하는 사용자 정의 그리드가 있습니다.
type
TpaGrid = class;
TpaColumnType = (ctText,ctDateTime,ctNumber,ctSize,ctPic,ctFileName);
TpaColumn = class(TCollectionItem)
private
FCaption: string;
FTitleFont: TFont;
FTitleAlignment: TAlignment;
FDataType : TPaColumnType;
FWidth: Integer;
FFont: TFont;
FColor: TColor;
FBackColor: TColor;
FAltBackColor: TColor;
FAlignment: TAlignment;
FPosition : integer;
FSortOrder : integer; // 0=no sort, 1=first, 2=second, etc...
FSortAscending : boolean;
// .... and many other interesting attributes
public
// ... published properties
end;
TpaColumnClass = class of TPaColumn;
TpaColumns = class(TCollection)
private
FGrid: TPaGrid;
// ... Getters and Setters, exposing the items as columns
public
constructor Create(grid:TPaGrid; ColumnClass: TPaColumnClass);
function AddColumn: TPaColumn;
// ... Load and Save procedures
// ... published properties
end;
TpaGrid = class (TStringGrid)
// ... overriden methods WMSize, DrawCell, ...
// ... getters and setters
private
FColumns : TpaColumns;
// ...
end;