Autor Beitrag
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 13:05 
Hallo,

ich erstelle zur Laufzeit Einträge in ein Pupup.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  //Eintrag in das PopUp
  for i := 0 to ListBox1.Count - 1 do
   begin
    eintrag := ListBox1.Items.Strings[i];
    PopUpMenu1.Items.Add(NewItem(Eintrag, i, false, true, MenuClick, 0, ''));
 //   popupmenu1.Items.Add((FindComponent('Mitarbeiterinformationen'+IntToStr(i)) as TMenuItem));
   end;
 finally  end;


Nun möchte ich das die Einträge als Submenüeintrag erfolgen. Dazu habe ich den Auskommentierden Teil im Netz gefunden.
Aber damit komme ich nicht klar.

Wie löse ich mein Problem?

Gruß Mexx
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 01.12.05 13:32 
ausblenden Delphi-Quelltext
1:
PopUpMenu1.Items[0].Add(NewItem(Eintrag, i, false, true, MenuClick, 0, ''));					

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 13:35 
Listenindex überschreitet das Maximum 0
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 01.12.05 13:37 
dann musst du den ersten als "Träger" für die subitems "add"en

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 13:40 
Ich habe zwei Items.

Beenden
Mitarbeiterinformationen

In dieser Reihenfolge. Mita* hat ein Untermenü. Ob Items[0] oder [1]. Ich erhalte die Fehlermeldung.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 01.12.05 13:48 
dann Name von Mitarbeiterinformationen.Add ();

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 13:52 
:cry:

Zugriffsverletzung
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 01.12.05 13:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
    beenden1: TMenuItem;
    Mit1: TMenuItem;



procedure TForm1.SpeedButton1Click(Sender: TObject);
  function NewItem (ACap: String): TMenuItem;
  begin
    Result := TMenuItem.Create(PopupMenu1);
    Result.Caption := ACap;
  end;
begin
  Mit1.Add(NewItem('1'));
  Mit1.Add(NewItem('2'));
end;
klappt bei mir problemlos!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 13:58 
please, watch my source!

ausblenden 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:
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var i: integer;

begin
try
  //Ini verbinden
  config := TIniFile.Create('\\192.168.1.8\IP\config.ini');

  //Sectionen auslesen
  ListBox1.Clear;
  config.ReadSections(ListBox1.Items);
  PopUpMenu1.Items.Clear;

  //Eintrag in das PopUp
  for i := 0 to ListBox1.Count - 1 do
   begin
    eintrag := ListBox1.Items.Strings[i];
    Mitarbeiterinformationen1.Add(NewItem(Eintrag, i, false, true, MenuClick, 0, ''));

   end;
 finally  end;

config.Free;

end;
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 01.12.05 14:01 
ausblenden 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:
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var i: integer;

begin
try
  //Ini verbinden
  config := TIniFile.Create('\\192.168.1.8\IP\config.ini');

  //Sectionen auslesen
  ListBox1.Clear;
  config.ReadSections(ListBox1.Items);
  Mitarbeiterinformationen1.Clear;  //hier

  //Eintrag in das PopUp
  for i := 0 to ListBox1.Count - 1 do
   begin
    eintrag := ListBox1.Items.Strings[i];
    Mitarbeiterinformationen1.Add(NewItem(Eintrag, i, false, true, MenuClick, 0, ''));

   end;
 finally  end;

config.Free;

end;

könnte gehen!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 14:06 
Ich bin ein Depp! :autsch:

Is ja logisch, wenn ich das Popup clear, dann kann das nix werden.

THX!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 01.12.05 14:13 
Ich habe aber noch ein geiles Teil. Pass auf.

Wie Du gesehen hast lese ich eine Ini aus. Die Einträge sehen so aus.

[name1]
IP=111.1.1.1.
PC=Rechnername
[name2]
IP=...
PC=...


Alles soweit OK. Ich lese die Inhalte der Ini so aus.

ausblenden Delphi-Quelltext
1:
config.ReadSections(ListBox1.Items);					


Die Einträge der Listbox stehen dann wie erwartet so drin.

name1
name2

ABER, jetzt kommts: Im Popup gibt es ein paar Einträge mit Zusatz.

Zum Beispiel:

name1 ROLLEN-FESTSTELL
name2 //ohne Zusatz
name3 ENTER
name4 5 (ZEHNERTASTUR)
name6
name7
name8 //alle ohne Zusatz


Diese Zusätze sehen aber werder in der Ini, noch im Listbox. Wo kommen die nur her?
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: Do 01.12.05 14:35 
Hallo,

in deinem Code verwendest Du deine Zählvariable im zweiten Argument von NewItem.
NewItem(Eintrag, i, false, true, MenuClick, 0, '')
Das zweite Argument ist: AShortCut: TShortCut;
Da ist die Quelle deiner Einträge.
Im OI bei der Eigenschaft ShortCut eines PopUp-Menüs findst Du sie auch.

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



BeitragVerfasst: Do 01.12.05 14:41 
:?!?:

[2. Beitrag]
Das i brauche ich doch aber auch. Wie sollte ich ohne dem?

[3. Beitrag]
Ne, sorry..alles klar! :lol:

Moderiert von user profile iconraziel: 3 Beiträge zusammengefasst.