Autor Beitrag
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 21.08.02 16:10 
matze hat folgendes geschrieben:
Das funzt allerdings auch nicht :cry:

Was kommt denn für eine Fehlermeldung?
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 21.08.02 16:45 
wenn ich TpopUpMenu1. benutze, kommen viele Fehlermeldungen: Z.B.
Fehler: . gefunden aber ; erwartet
Undefinierter Bezeicher: sender
Undefinierter Bezeicher: self


Wenn ich TForm1. beutze kommt nur
URLklick ist ein undefinierter Bezeichner und er markiert folgende stelle rot: mi.OnClick := UrlClick;

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 21.08.02 22:59 
Wie heißt denn jetzt die Form in der Du diese Procedure implementieren willst/hast? tPopUpMenu1 oder tForm1?
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 22.08.02 08:42 
halt stopp !!! ich hab den fehler gefunden !!!!

Ich hatte nicht, wie in dem Wuellext von MatthiasSimmack die Funktioenen für das laden des Menüs in Form1.Create, sondern ich hab das komplette Zeugs in eine eigene Procedure reingeschrieben. Ich hab jetzt das aus der Procedure ausgenmmen und in Form1. Create reingeschrieben und alles funzt bestens !!!

Aber: wie muss ich das ändern, wenn ich das in eine eigene Procedure reinschreiben will: also z.B:

ausblenden volle Höhe 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:
procedure Menuladen; 
var 
  cIni : TIniFile; 
  sl   : TStringList; 
  i    : integer; 
  mi   : TMenuItem; 
begin 
  cIni := TIniFile.Create(Filename); 
  with cIni do 
    try 
      sl := TStringList.Create; 
      try 
        ReadSections(sl); 

        if(sl.Count > 0) then 
          for i := 0 to sl.Count - 1 do 
            begin 
              mi         := TMenuItem.Create(nil); 
              mi.Caption := ReadString(sl.Strings[i],'name',''); 
              mi.Hint    := ReadString(sl.Strings[i],'url',''); 

              if(mi.Caption <> '') and (mi.Hint <> '') then 
                begin 
                  mi.OnClick := UrlClick; 
                  PopupMenu1.Items.Add(mi); 
                end; 
            end; 
      finally 
        sl.Free; 
      end; 
    finally 
      Free; 
    end; 
end;

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 22.08.02 09:17 
Du musst Deine Procedure Menuladen so umbauen das diese das PopupMenu und den Dateinamen als Parameter bekommt.
ausblenden volle Höhe 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:
procedure Menuladen (aPopupMenu: tPopupMenu; aFilename: String); 
var 
 cIni : TIniFile; 
 sl  : TStringList; 
 i  : integer; 
 mi  : TMenuItem; 
begin 
 cIni := TIniFile.Create(aFilename); 
 with cIni do 
  try 
   sl := TStringList.Create; 
   try 
    ReadSections(sl); 

    if(sl.Count > 0) then 
     for i := 0 to sl.Count - 1 do 
      begin 
       mi     := TMenuItem.Create(nil); 
       mi.Caption := ReadString(sl.Strings[i],'name',''); 
       mi.Hint  := ReadString(sl.Strings[i],'url',''); 

       if(mi.Caption <> '') and (mi.Hint <> '') then 
        begin 
         mi.OnClick := UrlClick; 
         aPopupMenu.Items.Add(mi); 
        end; 
      end; 
   finally 
    sl.Free; 
   end; 
  finally 
   Free; 
  end; 
end;

Im Event FormCreate kannst Du dann diese Procedrue aufrufen:
ausblenden Quelltext
1:
2:
3:
4:
Procedure tForm1.FormCreate (aSender: tObject);
Begin
  MenuLaden (PopupMenu1, 'c:\test.ini');
End;

Gruß
TINO

PS: Ich hoffe das das funktioniert... hab es nicht getestet!
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 22.08.02 09:23 
und wie muss ich dann die Funktion URLklick umbauen ??

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 22.08.02 11:07 
Stimmt das OnClick-Event habe ich vergessen. Das OnClick-Event ist vom Type TNotifyEvent. Das heißt das Du der Menuladen Procedure einen weiteren Parameter übergeben musst: nämlich das OnClickEvent und diesen Parameter kannst Du dann den OnClickEvents der MenuItems zuweisen.

Wenn Du die Procedure dann aufrufst müsste das ungefähr so aussehen:
ausblenden Quelltext
1:
2:
3:
4:
Procedure tForm1.FormCreate (aSender: tObject);
Begin
 MenuLaden (PopupMenu1, UrlClick 'c:\test.ini');
End;
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 22.08.02 13:13 
also die URLKlick routine kann ich unverändert lassen, richtig ???

Köntest du mal den neuen Quellcode der Load Routine und der URLKlick Routine posten !!! Das würe mir sehr helfen !!!

Danke !!!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 22.08.02 17:08 
Boah, mattttttttttttze :wink: Was sind das denn für Fragen?

Die "UrlClick"-Routine kann unverändert bleiben, weil du sie ja ganz offensichtlich nicht verändert sondern einfach nur aufgerufen hast, s.:
ausblenden Quelltext
1:
mi.OnClick := UrlClick;					

Durch die Benutzung des "OnClick" ist die Syntax für die Funktion (oder besser: Prozedur) ja bereits vorgegeben.

Wenn du deine "Menuladen"-Routine auch noch als private Form-Prozedur deklarierst:
ausblenden Quelltext
1:
procedure TDEINEFORM.Menuladen(aFilename: string);					

kannst du a) die Angabe des Popupmenüs direkt im Code unterbringen, weil die Prozedur nun ja auf die Form-Komponenten zugreifen kann (oder du lässt es so wie Tino vorschlägt, was die Funktion universell für andere Programme einsetzbar machen würde), und b) dürfte es keine Probleme geben, wenn du die "OnClick"-Funktion festlegst (s. Codeauszug oben)
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Fr 23.08.02 08:23 
danke !!!

Ich werds mal testn !!! :D

_________________
In the beginning was the word.
And the word was content-type: text/plain.