| Autor |
Beitrag |
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Sa 15.04.06 14:57
Hallo,
ich erstelle dynamische Buttons
Delphi-Quelltext 1:
| BtnLoeschenArray[i]:=TButton.Create(form1); |
Und ich will jedem eine OnClick-Procedure zuweisen:
Delphi-Quelltext 1: 2: 3: 4:
| procedure DeleteSubject(row : integer); OnClick:=???; |
Wie muss man den Code vervollständigen?
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
alias5000
      
Beiträge: 2145
WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
|
Verfasst: Sa 15.04.06 15:06
Huch? Ich glaub, du stehst grad einfach auf dem Schlauch, kann das sein?
Also du erstellst einfach eine Procedure, wie so eine (Parameter müssen stimmen!):
Delphi-Quelltext 1: 2: 3: 4:
| Procedure DynButtonClick(Sender: TObject); begin (Sender as TButton).Caption := 'Dynamischer Button'; end; |
Die Zuweisung geht dann so:
Delphi-Quelltext 1: 2: 3: 4:
| Procedure CreateAButton(i: integer); begin DynButtonArray[i] := TButton.Create(Self); DynButtonArray[i].OnClick := DynButtonClick; |
Hilft dir das weiter?
_________________ Programmers never die, they just GOSUB without RETURN
|
|
Born-to-Frag
      
Beiträge: 1094
Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
|
Verfasst: Sa 15.04.06 15:06
DynButton.OnClick := DeleteSubject;
_________________ Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
|
|
der Berliner
      
Beiträge: 417
Win Xp Home
delphi 2005
|
Verfasst: Sa 15.04.06 15:07
Hallo.
Ich denke mal das hier hast du schon gelesen oder?
www.delphi-forum.de/...t=dynamische+buttons
Gruß
_________________ [b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
|
|
alias5000
      
Beiträge: 2145
WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
|
Verfasst: Sa 15.04.06 15:13
Born-to-Frag hat folgendes geschrieben: | | DynButton.OnClick := DeleteSubject; |
Die Parameter stimmen aber nicht überein. Delete Subect hat als Parameter (ARow: integer) Ein TButton erwartet aber en TNotify-Event. Dies ist deklariert als
Delphi-Quelltext 1:
| TNotifiyEvent = Procedure(Sender: TObject); |
Entsprechend kannst du auch nix anderes übergeben, sollte eigentlich einen Compilerfehler geben.
So und jetzt stell ich mal den Besserwissermodus ab.. 
_________________ Programmers never die, they just GOSUB without RETURN
|
|
Marco D. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Sa 15.04.06 15:16
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Marco D. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Sa 15.04.06 15:18
Die Proceudre ist so deklariert:
Quelltext 1:
| procedure DeleteSubject(Sender : TObject); |
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
alias5000
      
Beiträge: 2145
WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
|
Verfasst: Sa 15.04.06 15:26
_________________ Programmers never die, they just GOSUB without RETURN
|
|
Marco D. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Sa 15.04.06 15:45
Also ich habe eine Unit functions.pas in der bisher zwei Procedures deklariert werden:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| unit functions;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ComCtrls;
procedure AddSubjects( number : integer); procedure DeleteSubject(Sender : TObject);
implementation |
Letztere soll einem dynamisch erstellten Button als OnClick-Ereignis zugewiesen werden:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| BtnLoeschenArray[i]:=TButton.Create(form1); with BtnLoeschenArray[i] do begin left:=5; width:=20; top:=i*50; parent:=form1.scrollbox1; caption:='X'; Tag:=i; OnClick:=???; end; |
Kann mir jemand weiterhelfen?
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
mkinzler
      
Beiträge: 4106
Erhaltene Danke: 13
Delphi 2010 Pro; Delphi.Prism 2011 pro
|
Verfasst: Sa 15.04.06 16:07
Hallo Marco,
Alias 500 hat dir oben doch gesagr das ein NotifyEvent eine Methode sein muß. Du mußt das also als Methode und nicht als Funktion deklarieren.
_________________ Markus Kinzler.
|
|
Marco D. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Sa 15.04.06 16:09
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Marco D. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Sa 15.04.06 16:17
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
mkinzler
      
Beiträge: 4106
Erhaltene Danke: 13
Delphi 2010 Pro; Delphi.Prism 2011 pro
|
Verfasst: Sa 15.04.06 16:18
Dir Procedure muß Teil einer Klasse sien, im Normalfall eine Formularklasse. Du mußt also, wenn du bei deinem Schema bleibst, in der externen Unit eine Klasse mit den Eventhandler-Routinen deklarieren:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
| unit functions;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ComCtrls;
TDyEvents = class public procedure TDynEvents.AddSubjects( number : integer); procedure TDynEvents.DeleteSubject(Sender : TObject); ... end;
implementation |
_________________ Markus Kinzler.
|
|
|