Autor Beitrag
µaTh
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 21.02.06 13:22 
Hallo DF-Community,

ich möchte gerne buttons erschaffen, auf die ich dann wie ein array zugreifen kann

so z.b.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
//global:
var buttons: array [1..3] of TButton;

procedure TForm1.formcreate(sender:tobject);
var i: byte;
begin
  for i:=1 to 3 do begin
    buttons[i]:=TButton.create(self);
    buttons[i].left:=i*50;
    buttons[i].top:=50;
    buttons[i].width:=50;
    buttons[i].name:='Button'+inttostr(i);
  end;
end;


jedoch wird nach dem start kein button angezeigt.

kann mir da jemand bitte helfen?

viele grüße
µaTh
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Di 21.02.06 13:35 
du brauchst noch die properties height und parent (parentwindow oder so. was genau weiss ich grad nicht ;-))


gruss daniel
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Di 21.02.06 13:36 
ausblenden Delphi-Quelltext
1:
buttons[i].Parent:=Form1;					
µaTh
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 21.02.06 16:37 
supi. danke.
Volker400
Hält's aus hier
Beiträge: 8

Win XP
Delphi 7
BeitragVerfasst: Mo 22.05.06 21:56 
Sorry, nur noch eine Frage dazu. Die Suchfunktion hat bei mir keinen Erfolg gebracht.

Wie kann ich jetzt für ein Button ein Ereignis wie "OnClick" oder so aufrufen lassen???

Danke im Voraus!!!

Gruß Volker
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Mo 22.05.06 22:02 
Du schreibst eine Prozedur mit passenden Parametern (bei OnClick ist es glaube ich Sender: TObject) und dann folgende Zeile:

ausblenden Delphi-Quelltext
1:
Button[i].OnClick:=BtnProcedure;					
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: Mo 22.05.06 22:07 
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:
34:
35:
36:
37:
38:
39:
...
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  buttons: array [1..3] of TButton;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i: byte;  
begin  
  for i:=1 to 3 do begin
    buttons[i]:=TButton.create(self);
    buttons[i].left:=i*50;  
    buttons[i].top:=50;  
    buttons[i].width:=50;  
    buttons[i].name:='Button'+inttostr(i);
    buttons[i].Parent:=Form1;
    buttons[i].OnClick:=ButtonClick; //hier keine Parameter
  end;
end;

procedure TForm1.ButtonClick(Sender: TObject);
begin
Edit1.Text:=TButton(Sender).Caption;
end;
...

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
Volker400
Hält's aus hier
Beiträge: 8

Win XP
Delphi 7
BeitragVerfasst: Mo 22.05.06 22:10 
Hy, danke für die schnelle Antwort.

Ja, hat jetzt geklappt!!! Hatte schon einiges durch. Doch zum Testen sollte man evtl. auch mal eine Aufgabe durchführen lassen :oops: , da sonst sofort die Procedure wieder entfernt wird.

DANKE!!! :beer: