Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 15.04.06 14:57 
Hallo,

ich erstelle dynamische Buttons
ausblenden Delphi-Quelltext
1:
BtnLoeschenArray[i]:=TButton.Create(form1);					

Und ich will jedem eine OnClick-Procedure zuweisen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
//Diese will ich zuweisen:
procedure DeleteSubject(row : integer);
//Zuweisung:
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
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
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)
BeitragVerfasst: 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!):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Procedure DynButtonClick(Sender: TObject);
begin
(Sender as TButton).Caption := 'Dynamischer Button';
end;


Die Zuweisung geht dann so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Procedure CreateAButton(i: integer);
begin
DynButtonArray[i] := TButton.Create(Self);
DynButtonArray[i].OnClick := DynButtonClick; //Zuweisung ohne irgendwelche Parameter aufzuführen

Hilft dir das weiter?

_________________
Programmers never die, they just GOSUB without RETURN
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: 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
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
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)
BeitragVerfasst: Sa 15.04.06 15:13 
user profile iconBorn-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
ausblenden 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.. :wink:

_________________
Programmers never die, they just GOSUB without RETURN
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 15.04.06 15:16 
Ich hab es jetzt gemacht wie alias5000:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
    //1. Fehler:
    BtnLoeschenArray[i]:=TButton.Create(self);
    with BtnLoeschenArray[i] do
    begin
      left:=5;
      width:=20;
      top:=i*50;
      parent:=form1.scrollbox1;
      caption:='X';
      Tag:=i;
     //2. Fehler:
      OnClick:=DeleteSubject;
    end;

:motz: Jetzt kriege ich aber mehr Fehler als vorher :-(
Zitat:

1. functions.pas(42): Undefinierter Bezeichner: 'self'
2. functions.pas(51): Inkompatible Typen: 'Methodenzeiger und reguläre Prozedur

_________________
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. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 15.04.06 15:18 
Die Proceudre ist so deklariert:
ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
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)
BeitragVerfasst: Sa 15.04.06 15:26 
user profile iconMarco D. hat folgendes geschrieben:
Ich hab es jetzt gemacht wie alias5000:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
    //1. Fehler:
    BtnLoeschenArray[i]:=TButton.Create(self);
    with BtnLoeschenArray[i] do
    begin
      left:=5;
      width:=20;
      top:=i*50;
      parent:=form1.scrollbox1;
      caption:='X';
      Tag:=i;
     //2. Fehler:
      OnClick:=DeleteSubject;
    end;

:motz: Jetzt kriege ich aber mehr Fehler als vorher :-(
Zitat:

1. functions.pas(42): Undefinierter Bezeichner: 'self'
2. functions.pas(51): Inkompatible Typen: 'Methodenzeiger und reguläre Prozedur


Also dass self nicht bekannt ist, liegt daran, dass ich davon ausgegangen bin, du würdest dass in einer Unit machen in der die entsprechende Form steckt. Trag da am besten sowas wie Form1 ein.

Zum zweiten: da muss ich ohne Delphi leider auch passen, tut mir echt leid, mein Delphi-PC ist halt grad kapputt :-(
Obwohl, kann das was damit zu tun haben, wo die Procedure deklariert ist? Deklarier sie doch mal als TForm1.DeleteSubject, iss aber nur ein Tipp ins blaue

_________________
Programmers never die, they just GOSUB without RETURN
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 15.04.06 15:45 
Also ich habe eine Unit functions.pas in der bisher zwei Procedures deklariert werden:
ausblenden 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:
ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: 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. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 15.04.06 16:09 
user profile iconmkinzler hat folgendes geschrieben:
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.

Da steht doch aber procedure und nicht function :gruebel: :nixweiss:
Was meinst du? :autsch:

_________________
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. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 15.04.06 16:17 
:twisted: :twisted: :twisted:
Ich habe jetzt die Procedure DeleteSubjects in die Unit der Hauptform umgelagert und dann gings.
:twisted: :twisted: :twisted:

_________________
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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: 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:

ausblenden 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.