Autor Beitrag
Jojojoxx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 11:34 
Hallo!

Ich möchte gerne Items eines Untermenüs einer Popup-Komponente zur Laufzeit erstellen lassen.
Dies ist mir bisher nur bedingt gelungen.
Mit folgendem Code gelingt es mir, die Items im Hauptmenü des Popup unterzubringen, jedoch weiß ich nicht, wie ich auf ein Untermenü zugreifen kann:

ausblenden Quelltext
1:
   Form1.PopUpMenu1.Items.Add(NewItem(Name, i, false, true, MenuClick, 0, ''));					

Kann mir da jemand weiterhelfen?
Danke euch!

mfg

Jojo
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 30.07.06 12:30 
Hallo,

da muss man das entsprechede Item des PopUp-Menüs ansprechen,
Untermenü zum ersten Item des PopUp-Menüs hinzufügen:
ausblenden Delphi-Quelltext
1:
PopupMenu1.Items[0].Add(NewItem(Name, i, false, true, MenuClick, 0''));					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 12:36 
Ahh super!! Hat funktioniert!
Vielen Dank!

mfg
Jojo
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 12:45 
Hi!

Ich habe noch eine weitere Frage:
Wie kriege ich nun raus, welcher Punkt im Popup gewählt wurde?
Habe dazu das hier gefunden:

ausblenden Quelltext
1:
2:
3:
4:
procedure TForm1.MenuClick(Sender: TObject);
begin
  ShowMessage((Sender as TMenuItem).Caption);
end;


Allerdings klappt es nicht ganz.
Zuerst ist MenuClick ein undefinierter bezeichner.
Nachdem ich unter type procedure MenuClick(Sender: TObject);
hinzugefügt habe, startet das Programm zwar, aber bei einem Klick auf ein Item
erscheint keine showmessage.

MenuClick ist eine globale Variable des Typen TNotifyEvent

Danke für die Hilfe!

mfg

Jojo
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 30.07.06 12:55 
Hallo,

so wie Du das beschreibst müsste es eigentlich funktionieren.
Hier mal ein Beispiel, damit funktioniert es:
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    PopupMenu1: TPopupMenu;
    irgendwas1: TMenuItem;
    procedure Button1Click(Sender: TObject);
    procedure MenuClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
PopupMenu1.Items[0].Add(NewItem('Untermenü1'0, false, true, MenuClick, 0''));
end;

procedure TForm1.MenuClick(Sender: TObject);
begin
  ShowMessage((Sender as TMenuItem).Caption);
end;

end.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 13:15 
Hi!

Dein Code funktioniert in der Tat (du hast nur vergessen MenuClick als TNotifyEvent zu deklarieren).
Habe auf die Schnelle keinen Unterschied zu meinem Code gefunden, aber ich werde jetzt mal genauer suchen.
Danke soweit!

mfg

Jojo
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 13:29 
Hi!

Habe gerade herausgefunden, dass es bei mir nur dann nicht klappt, wenn die Items in einer selbstgeschriebenen Prozedur erstellt werden, also keiner Prozedur, die mit "TForm1." beginnt.
Wie kann ich das ändern?
Danke euch!

mfg

Jojo
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 30.07.06 13:37 
Indem du Form1 vor die Komponente schreibst.

_________________
Markus Kinzler.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 13:48 
Es funktioniert auch nicht, wenn ich Form1 davor schreibe (was ich auch so hatte).

Wenn ich nicht Form1 davorstehen hätte, würde ja der Compiler die Fehlermeldung "Undefinierter Bezeichner PopupMenu1" rausgeben.

mfg

Jojo
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 30.07.06 13:59 
Du mußt den Namen des Formobjektes auch in der Parameterliste für die Angabe der Event,ethode ergänzen.

_________________
Markus Kinzler.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 14:06 
Wenn du diese Zeile meinst:

ausblenden Quelltext
1:
procedure TForm1.MenuClick(Sender: TObject);					

dann habe ich das bereits getan.
Diese Prozedur soll gestartet werden, wenn auf ein Item geklickt wird.

mfg

jojo
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 30.07.06 14:19 
Nein ich meint hier

ausblenden Delphi-Quelltext
1:
Form1.PopupMenu1.Items[0].Add(NewItem('Untermenü1'0, false, true, Form1.MenuClick, 0''));					

_________________
Markus Kinzler.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 30.07.06 14:22 
Jaaaa :) Es klappt!
Vielen Dank!!!

mfg

Jojo