Hallo,
ich füge mit folgendem Code einen Button in eine StringGrid ein:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| procedure TForm1.InsertButtonIntoCell(X,Y: Integer); var Button: TButton; CellsTop, CellsLeft, i: Integer; begin CellsTop := Y; CellsLeft := X;
Button := TButton.Create(StringGrid1);
button.top := 0; for i := 0 to CellsTop-1 do begin button.Top := button.Top + stringgrid1.Rowheights[i]+1; end; button.height := stringgrid1.RowHeights[CellsTop];
button.left := 0; for i := 0 to CellsLeft-1 do begin button.Left := button.Left + stringgrid1.ColWidths[i]+1; end; button.Width := stringgrid1.ColWidths[CellsLeft];
button.Caption := 'bearbeiten'; button.Tag := Y; button.OnClick := ClickProc; StringGrid1.InsertControl(Button); end;
procedure TForm1.ClickProc ( Sender: TObject); begin showmessage(IntToStr(TButton(Sender).Tag)); messagedlg('HALLO',mtWarning,[mbOk],0); end; |
Beim Klicken auf den erzeugten Button soll die Prozedur ClickProc aufgerufen werden. Das funktioniert aber nicht - wenn ich den Button nicht im StringGrid sondern direkt auf der Form erzeuge klappt es. Hat jemand einen Vorschlag?