Einzelnen Beitrag anzeigen

Christian18

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

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

  Alt 18. Mär 2008, 11:42
Hallo,

ich bins nochmal.

Wenn ich ein Object in public Deklariere und auch zuweise, dann solle ich in der erbende klasse doch darauf zurgreifen können oder?

Delphi-Quellcode:
unit UMainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, XMLDoc, UProgram;

type
  TFMainForm = class(TForm)
    PMain: TPanel;
    ITop: TImage;
    IBottom: TImage;
  private
    Prg: TProgram;
    FMenuBtn: Array of TImage;
    FMenuText: Array of TLabel;
    { Private-Deklarationen }
  public
    FMenuActive: TImage; // hier dekl. ich es
    procedure CreateMenu(AForm: TForm; AClass : TClass);
    procedure MoveMenu(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure LeaveMenu(Sender: TObject);
    { Public-Deklarationen }
  end;

var
  FMainForm: TFMainForm;

implementation

{$R *.dfm}

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(PMain);
          FMenuText[i - 1]:=TLabel.Create(PMain);

          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]; // hier weise ich es zu
                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;

procedure TFMainForm.MoveMenu(Sender: TObject; Shift: TShiftState; X: Integer; Y: Integer);
  var Item : String;
begin
  Item:=TComponent(Sender).Name;
  Item[1]:='I';
  TImage(PMain.FindComponent(Item)).Picture.LoadFromFile(Prg.GetAppPath + 'Img\BtnMove.bmp');
end;

procedure TFMainForm.LeaveMenu(Sender: TObject);
  var Item : String;
begin
  Item:=TComponent(Sender).Name;
  Item[1]:='I';
  TImage(PMain.FindComponent(Item)).Picture.LoadFromFile(Prg.GetAppPath() + 'Img\BtnLeave.bmp');
  FMenuActive.Picture.LoadFromFile(Prg.GetAppPath() + 'Img\BtnMove.bmp'); // hier benutze ich es nochmal, damit das active image weiter leuchtet auch wenn mit der mouse wieder runter gefahren wird
end;

end.
  Mit Zitat antworten Zitat