TStringGridを上位クラスにした、コンポーネントの各セルごとにプロパティを持たせたいのですが
良い方法はないでしょうか。イメージとしては、コンポーネント呼び出し側で、
ABCGrid.Cell[X,Y].aa_property=XXXみたいなことをしたいのですが、不可能でしょうか?
グリッドのプロパティに二次元配列を追加することはできないようなので他の方法を探しています。
どうぞよろしくお願いします。
できますよ、配列。
Get関数と、Setプロシージャを用意しましょう。直接代入は無理です。
FCellProperty: TStringList;
function GetCellProperty(ACol, ARow: Integer): string;
procedure SetCellProperty(ACol, ARow: Integer; const Value: string);
property CellProperty[ACol, ARow: Integer]: string read GetCellProperty write SetCellProperty;
function TStringGridEx.GetCellProperty(ACol, ARow: Integer): string;
var
Row: TStringList;
begin
while FCellProperty.Count < ARow + 1 do
begin
FCellProperty.Add('');
end;
Row := TStringList.Create;
Row.CommaText := FCellProperty.Strings[ARow];
while Row.Count < ACol + 1 do
begin
Row.Add('');
end;
Result := Row.Strings[ACol];
Row.Free;
end;
procedure TStringGridEx.SetCellProperty(ACol, ARow: Integer; const Value: string);
var
Row: TStringList;
begin
while FCellProperty.Count < ARow + 1 do
begin
FCellProperty.Add('');
end;
Row := TStringList.Create;
Row.CommaText := FCellProperty.Strings[ARow];
while Row.Count < ACol + 1 do
begin
Row.Add('');
end;
Row.Strings[ACol] := Value;
FCellProperty.Strings[ARow] := Row.CommaText;
Row.Free;
end;
こんな感じです。
FCellPropertyの初期化・解放を忘れずに。
できました。ありがとうございます。
ツイート | ![]() |