Einzelnen Beitrag anzeigen

Christian18

Registriert seit: 9. Dez 2003
Ort: Hamburg
1.279 Beiträge
 
#18

Re: Prüfen, ob eine Klasse eine bestimmte Methode enthält

  Alt 17. Mär 2008, 21:38
Hallo,

ich denke schon, dass ich das Objekt erzeuge. Bloß an einer anderen Stelle. Nämlich wenn die form erzeugt wird:

FMenuActive ist der Active Button, der leuchten soll.

Delphi-Quellcode:
procedure TFMainForm.CreateMenu(AForm: TForm; AClass : TClass);
  var lXml: TXMLDocument;
      Count: Word;
      i: Word;
      Method: TMethod;
begin
  lXml:=TXMLDocument.Create(Application);
  try
    Prg:=TProgram.Create();
    try
      lXml.LoadFromFile(Prg.GetAppPath() + 'Settings\Menu.xml');

      Count:=lXml.DocumentElement.ChildNodes[AForm.Name].ChildNodes.Count;
      SetLength(FMenuBtn, Count);
      SetLength(FMenuText, Count);
      for i:=1 to Count do
        begin
          FMenuBtn[i - 1]:=TImage.Create(AForm);
          FMenuText[i - 1]:=TLabel.Create(AForm);

          with FMenuBtn[i - 1] do
            begin
              Name:='IItem' + IntToStr(i);
              Width:=100;
              Height:=75;
              Left:=PMain.Width - Count * Width - (Count - 1) * 8 + (i - 1) * Width + (i - 1) * 8;
              Top:=0;
              if i = 1 then
                begin
                  Picture.LoadFromFile(Prg.GetAppPath() + 'Img\BtnMove.bmp');
                  FMenuActive:=FMenuBtn[i - 1];
                end
              else
                begin
                  Picture.LoadFromFile(Prg.GetAppPath() + 'Img\BtnLeave.bmp');
                end;

              Method.Data:=FMenuBtn[i - 1];
              Method.Code:=AClass.MethodAddress(lXml.DocumentElement.ChildNodes[AForm.Name].ChildNodes[i - 1].Attributes['OnClick']);
              OnClick:=TNotifyEvent(Method);

              OnMouseMove:=MoveMenu;
              OnMouseLeave:=LeaveMenu;

              Parent:=PMain;
            end;

          with FMenuText[i - 1] do
            begin
              Name:='LItem' + IntToStr(i);
              Left:=FMenuBtn[i - 1].Left + 4;
              Top:=57;
              Caption:=lXml.DocumentElement.ChildNodes[AForm.Name].ChildNodes[i - 1].Attributes['Caption'];
              Transparent:=True;

              Method.Data:=FMenuBtn[i - 1];
              Method.Code:=AClass.MethodAddress(lXml.DocumentElement.ChildNodes[AForm.Name].ChildNodes[i - 1].Attributes['OnClick']);
              OnClick:=TNotifyEvent(Method);

              OnMouseMove:=MoveMenu;
              OnMouseLeave:=LeaveMenu;

              Parent:=PMain;
            end;
        end;
    finally
      Prg.Free();
    end;
  finally
    lXml.Free();
  end;
end;
  Mit Zitat antworten Zitat