Thema: Delphi Problem beim Vererben

Einzelnen Beitrag anzeigen

Christian18

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

Re: Problem beim Vererben

  Alt 18. Mär 2008, 12:50
Fehler noch nicht gefunden. Das kleine Bsp. funktioniert nach deinem Tip. Aber das Große nicht.

Ist genauso aufgebaut wie das kleine beispeil

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;
    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];
                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');
end;

end.
Edit:

FMain erbt von FMainForm. In der Klasse TFMain wird bei OnCreate die Methode "CreateMenu" der Klasse FMainForm aufgerufen. Genauso wie im beispiel
  Mit Zitat antworten Zitat