Autor Beitrag
rob87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mo 17.09.07 12:38 
Hallo,
ich habe folgenden, kompliziert klingenden, Sachverhalt:

Ich habe eine Tabelle mit einer Spalte Menue_Name, in der die einzelnen Namen meines MainMenue aufgelistet sind.


Ich möchte nun folgendes: Für alle Zeilen in denen in der einen Spalte der Name des Menüpunktes steht, setze mir diesen MainMenue-Punkte beim OnCreate Enabled auf true.


Ich hoffe, ich konnte es einigermaßen verständlich erklären.
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Mo 17.09.07 13:49 
Versuch dich mal mit FindComponent!
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mo 17.09.07 15:48 
Und wie soll des funktionieren?

Ich hab mal nach FindComponent gegoogelt aber nix Verständliches gefunden.
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Mo 17.09.07 16:12 
Also wenn ich dich richtig verstanden habe sind die Menüeinträge alle schon da
und werden NICHT automatisch anhand der Tabelle erstellt.
Du willst sie nur anhand der Tabelle en- bzw. disablen.

Vielleicht war FindComponent nicht ganz das richtige Stichwort.
Hier mal eine Anregung wie es funktionieren sollte:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var i    : Integer;
    item : TMenuItem;
begin
  for i:=0 to ComponentCount-1 do
  begin
    if (Components[i] is TMenuItem) then
    begin
      item := (Components[i] as TMenuItem);
      if item.Caption = ... then
      begin
        // enable / disable
      end;
    end;
  end;
end;
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 18.09.07 07:59 
Bei TMenueItem bringt er mir die Fehlermeldung. Undefinierter Bezeichner.

So sieht mein Quellcode bisher aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
      for x := 0 to __.MainMenu1.Items.Count -1 do begin
        for y := 0 to __.MainMenu1.Items[x].Count -1 do begin

          if __.MainMenu1.Items.Caption = Tabellexy['Spaltexy']
            then
              begin

                //__.MainMenu1.Items.Enabled := true;

              end;
         end;
      end;


Kann ma deinen Beitrag nun sinnvoll bei mir einbauen?
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Di 18.09.07 08:11 
Du solltest die unit "Menus" einbauen, aber das hast du vermutlich schon.

Hast du auf eine Form ein MainMenu gesetzt oder willst du sie doch automatisch
erstellen? Wenn ja, dann such mal danach im Forum, da gibts was.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 18.09.07 08:27 
Das MainMenu1 ist Bestandteil eines TForm.

Ich nenns mal TForm1.

In meinem obigen Quelltxt verbirgt sich hinter dem "__" also die Unit des TForm1. Die Zeile sollte also so heißen: unitForm1.MainMenu1.(was auch immer)
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Di 18.09.07 11:28 
Dann müsstest du dort nicht den Unit-Namen, sondern den Form-Namen eintragen!

Allerdings kannst du dann nicht auf das MainMenu zugreifen, da dass im Normalfall
ein privates Feld ist.

Warum machst du das ganze nicht in der Form-Klasse selbst?
Oder, falls du es wirklich auseinanderziehen willst, dann solltest
du eine Schnittstelle anbieten.
(MainMenu public zumachen zeugt nicht von gutem Stil)
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 18.09.07 14:58 
Tut mir Leid, aber ich weiß nicht, was du meinst.
*g*
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Di 18.09.07 15:18 
Wie heißt den die Funktion, in der du die Zuordnung momentan aufrufst?
Ist das dieselbe Unit in der auch die Form steht auf der das MainMenu ist?
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 19.09.07 06:44 
Momentan nicht. Ich wollt des machen, dacht mir, aber dass es in den anderen einzelnen Formularen einfacher ist.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 19.09.07 06:51 
Also nochmal zusammengefasst:

Ich hab ein Formular, nennen wir es FormMenue1, welches beim Programmstart als allererstes geladen wird. (Nur !) in diesem Formular befindet sich das MainMenu1.

D.h. ich kann vom FormMenu1 aus die anderen "Unter-"Formulare öffnen.

Nun habe ich ein "Unter-"Formular welches mir ein Zugriffsteuerung der einzelnen Menüpunkte macht. D.h. mein Programm schaut entweder im Create jedes Formulares oder nur im Create des FormMenu1 (bzw. eben in einer Tabelle) nach, wie es mit den Zugriffen aussieht und setzt dementsprechend Menüpunkte auf Enabled := true oder false;


Die Tabelle enthält folgende für diesen Teil weichtige Daten:
Benutzer-Nummer, Programm-Name, Menuepunkt-Name und Zugriff (j oder n).

Delphi-Code des FormCreate momentan bei einem beliebigen "Unter-"Formular:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
      for x := 0 to FormMenu1.MainMenu1.Items.Count -1 do begin
        for y := 0 to FormMenu1.MainMenu1.Items[x].Count -1 do begin

          if FormMenu1.MainMenu1.Items.Caption = Tabelle1['Spalte Menue-Name']
            then
              begin

                //FormMenu1.MainMenu1.Items.Enabled := true;

              end;
         end;
      end;
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Mi 19.09.07 08:40 
Funktionierts jetzt?
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 19.09.07 09:12 
Nein, leider nicht.

Diese Zeile ist aus der Luft gegriffen, dass kann man bestimmt nicht so schreiben:
ausblenden Delphi-Quelltext
1:
if FormMenu1.MainMenu1.Items.Caption = Tabelle1['Spalte Menue-Name']					
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Mi 19.09.07 12:11 
user profile iconrob87 hat folgendes geschrieben:
dass kann man bestimmt nicht so schreiben


Das kommt ganz darauf an. Häng doch mal deinen Source als Zip an, dann
sieht man mal wie das gesamte Projekt ausschaut.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Do 20.09.07 08:41 
user profile iconarj hat folgendes geschrieben:
user profile iconrob87 hat folgendes geschrieben:
dass kann man bestimmt nicht so schreiben


Das kommt ganz darauf an. Häng doch mal deinen Source als Zip an, dann
sieht man mal wie das gesamte Projekt ausschaut.




Es funktioniert nun bereits halbwegs. Nur, dass ich keinen Wert in einem MainMenu.Items[x][y].Caption hab.

Aber das hab ich in nem anderen Thema reingeschrieben.

www.delphi-forum.de/...r=asc&highlight=