Autor Beitrag
mambo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 76

Win XP
D6 Prof
BeitragVerfasst: Do 20.02.03 08:52 
Hallo !

Ich habe folgendes Problem: Ich erstelle mir zur Laufzeit dynamisch aus einer Tabelle neue Menueinträge in meinem PopUpMenu.
Wie kann ich aber diesen neu erstellten Menueinträgen beim Ereignis OnClick eine Prozedur zuweisen???

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
while Query1.Eof = False do
begin
   NewItem := TMenuItem.Create(Self);
   NewItem.Caption := Query1.FieldByName('BESCHREIBUNG').AsString;
   NewItem.OnClick := ?????????????;
   PopUpMenu.Add(NewItem);
   Query1.Next;
end;


Danke
Heinz
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Do 20.02.03 09:10 
Hi,

vielleicht so?

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
private
  procedure MyMenuClick(Sender: TObject);
..
procedure TForm1.MyMenuClick(Sender: TObject);
...

menuitem.OnClick := MyMenuClick;


AXMD
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 20.02.03 09:13 
Ja :D

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
mambo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 76

Win XP
D6 Prof
BeitragVerfasst: Do 20.02.03 09:35 
Titel: OnClick Ereignis
Leider funktioniert das ganze so nicht!
bei
ausblenden Quelltext
1:
  NewItem.OnClick					


muß man einen TNotifyEvent zuweisen und nicht einfach eine Prozedur.

Ich erhalte die Fehlermeldung:
Inkompatible Typen: 'TNotifyEvent' und 'procedure'

HILFE!!!
mambo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 76

Win XP
D6 Prof
BeitragVerfasst: Do 20.02.03 09:38 
Titel: OK
JETZT FUNKTIONIERTS !!!

Hab nur falsch zugewiesen
statt
NewItem.OnClick := MyMenuClick(NewItem);
muß man einfach
NewItem.OnClick := MyMenuClick; zuweisen

DANKE !!!!
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Do 20.02.03 09:42 
Hallo,

der Typ ist folgendermaßen deklariert:

ausblenden Quelltext
1:
2:
type
  TNotifyEvent = procedure (Sender: TObject) of object;


Dies bedeutet, Deine Ereignissprocedure muss den gleichen Typ haben:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
  ...
  procedure MyMenueClick(Sender:TObject);
  ...



  ...
  NewItem.OnClick:=MyMenueClick;
  ...


procedure TForm1.MyMenueClick(Sender:TObject);
begin
  // Tue irgend etwas
end; // TForm1.MyMenueClick


Uups, dann hat sich mein Posting ja erledigt.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)