Autor Beitrag
thorbenZ
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Sa 23.08.03 14:20 
Hallo,

ich füge mit folgendem Code einen Button in eine StringGrid ein:

ausblenden volle Höhe Delphi-Quelltext
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?
recall
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 449



BeitragVerfasst: Sa 23.08.03 23:57 
ausblenden Quelltext
1:
Button := TButton.Create(StringGrid1);					

würde ich als
ausblenden Quelltext
1:
2:
Button := TButton.Create(Self); 
Button.Parent := StringGrid1;

schreiben. Müsste eigentlich egal sein, war es bei mir aber nie :D .

Viele Grüsse.

P.S.: Deswegen muss es nicht funktionieren, ist nur geraten ;) .
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: So 24.08.03 13:58 
wenn das nicht klappt, benenne doch mal button in button1 um

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
Shark
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 87

98, XP
D3, D5, D7
BeitragVerfasst: Do 28.08.03 21:48 
insertcontrol solltest Du nicht verwenden siehe Hilfe
arbeite mit Parent
Shark
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 87

98, XP
D3, D5, D7
BeitragVerfasst: Do 28.08.03 21:51 
und sie mal bei cellrect nach, dann kannst Du Dir die Schleifen sparen, die ausserdem die die gridlinewidth nicht berücksichtigen...