あなたが正しいです。列がどこにあるかを追跡する必要があります。おそらく別の構造体、または 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;
// ...
終わり;