Autor Beitrag
moloch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Mi 25.08.04 10:38 
Hallo,
ich erstelle mir ein PopUpMenue wärend der Laufzeit. Das klappt ja auch schon, aber
jetzt möchte ich auch gerne auf das click-ereignis des jeweils angelegten Items zugreifen.
Wie geht das?

mfg
moloch
teebee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 109


D6 Prof
BeitragVerfasst: Mi 25.08.04 11:58 
Du musst dem OnClick-Property des MenuItems eine Prozedur zuweisen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
Procedure TForm1.MyItemClick(Sender: TObject);
Begin
...
End;

...
MyItem.OnClick := MyItemClick;

Gruß, teebee
moloch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Mi 25.08.04 12:07 
hey,
das ist schon mal ein gute sache danke.
aber jetzt möchte ich in dem click-ereignis die caption von dem item wissen auf den ich gerade im popupmenü geklickt habe. das weiss ich leider auch nicht.
kannst du mir da noch mal helfen?
mfg
moloch
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mi 25.08.04 12:20 
ausblenden Delphi-Quelltext
1:
Itemtext:=(Sender as TMenuItem).Caption;					


Gruß,
Jörg
moloch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Mi 25.08.04 12:35 
hallo,
das ist super,es funktioniert.
aber: die caption kommt mit einem & als vorhang. kann ich das unterbinden?

mfg
moloch
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mi 25.08.04 12:37 
Keine Ahnung, warum das da steht, kann aber mit
ausblenden Delphi-Quelltext
1:
Itemtext:=Copy(Itemtext,2,Length(Itemtext));					

unterbunden werden.
teebee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 109


D6 Prof
BeitragVerfasst: Mi 25.08.04 14:06 
Das '&' steht vor dem Zeichen, das unterstrichen dargestellt wird, dem Tastaturkürzel:
Delphi-Hilfe hat folgendes geschrieben:
In der Eigenschaft Caption legen Sie den String fest, der zur Laufzeit für diesen Menüeintrag angezeigt wird. Wenn ein Zeichen unterstrichen dargestellt werden soll, stellen Sie ihm ein kaufmännisches Und (&) voran. Das unterstrichene Zeichen in einem Menüeintrag wird als Tastenkürzel bezeichnet. Wenn Sie in Caption ein derartiges Zeichen definieren, kann der Benutzer den Menüeintrag auswählen, indem er die ALT-Taste gedrückt hält und das unterstrichene Zeichen eingibt.
D.h. es kann an allen möglichen Positionen stehen und muss deshalb so entfernt werden:
ausblenden Delphi-Quelltext
1:
2:
ItemText := (Sender as TMenuItem).Caption;
If Pos('&',ItemText)<>0 Then Delete(ItemText,Pos('&',ItemText),1);
Gruß, teebee
moloch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Mi 25.08.04 14:53 
hey leute,
also es geht einfacher!
man muss die eigenschaft autohotkeys (vom popupmenü) auf manuell stellen.

mfg
moloch
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 25.08.04 14:54 
Zitat:
D.h. es kann an allen möglichen Positionen stehen und muss deshalb so entfernt werden
´Das Problem ist nur, dass dur Eingabe von "&&" erreicht wird, dass das zeichen als "Und" angezeigt wird, bei deiner func würde hier zum Beispiel was falsches rauskommen.

real caption: Status && &Optionen (Anzeige: Status & Optionen)
got caption: Status & &Optionen

imo wäre folgendes besser
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function Func(Itemtext: string): string;
var
 i: integer;
begin
ItemText := ' '+ItemText+' ';
for i := 1 to Length(Itemtext)-2 do
 if (Itemtext[i] = '&') and (Itemtext[i-1] <> '&') and (Itemtext[i+1] <> '&') then
 begin
  Delete(Itemtext, i, 1);
  break;
 end;
 result := Trim(ItemText);
end;


das "and (Itemtext[i+1] <> '&')" ausklammern wenn die "Doppel-&'s" auf eins verkürzt werden solllen (dann muss aber natürlich auch das break raus)

im allgemeinen sollte deine Lösung aber genügen :wink:

[edit]
Zitat:
man muss die eigenschaft autohotkeys (vom popupmenü) auf manuell stellen
und was ist, wenn er die Hotkeys aber haben möchte?[/edit]

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
moloch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Do 26.08.04 08:44 
hallo,
na dann muss man die eigenschaft auf automatic stellen

mfg
moloch
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Do 26.08.04 14:00 
Zitat:
na dann muss man die eigenschaft auf automatic stellen
womit wir wieder am Anfang währen
Zitat:
aber: die caption kommt mit einem & als vorhang. kann ich das unterbinden?
:shock: Ups...

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 26.08.04 14:14 
Dann musst du halt mehr Kreativität beim Benennen walten lassen. :roll: Der nächste Ansatz wäre ein Parser, weil man so einfach nicht alle möglichen Kombinationen mit und um & ausschließen kann.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Fr 27.08.04 07:18 
Hallo!

Aus welchem Grund möchtest du denn die Caption des gerade ausgewählten Menüpunkt haben? Möchtest du nur einfach unterscheiden welcher Menüpunkt ausgewählt wurde oder wofür brauchst du die Caption?

Gruß
Tino