グリッドセルの配列宣言

解決


monst  2004-03-06 11:43:42  No: 7592  IP: [192.*.*.*]

タイピング量を減らす目的で、
StringGrid1.Cells[i,j] を短く S[i,j]  という表現で参照することができますか?
そのとき配列 S をどのように宣言すればいいのですか?

編集 削除
jok  2004-03-06 13:29:47  No: 7593  IP: [192.*.*.*]

できますよ。見かけ上は。
フォームのプロパティーにするとよいです。

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    function GetCells(ACol, ARow: Integer): string;
    procedure SetCells(ACol, ARow: Integer; const Value: string);
  public
    property S[ACol, ARow: Integer]: string read GetCells write SetCells;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.GetCells(ACol, ARow: Integer): string;
begin
  result := StringGrid1.Cells[ACol,ARow];
end;

procedure TForm1.SetCells(ACol, ARow: Integer; const Value: string);
begin
  StringGrid1.Cells[ACol,ARow] := Value;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  S[3,3] := 'TEST';
  Label1.Caption := S[3,3];
end;

編集 削除
monst  2004-03-06 14:18:09  No: 7594  IP: [192.*.*.*]

迅速的確な御教示に、無限の感謝です!
jok様ありがとうございました。

編集 削除