Thema: Delphi Events zur Designtime

Einzelnen Beitrag anzeigen

Benutzerbild von LoCrux
LoCrux

Registriert seit: 5. Mär 2007
Ort: Gwang-Yang-City
48 Beiträge
 
Delphi 2009 Enterprise
 
#32

Re: Events zur Designtime

  Alt 19. Mär 2008, 12:35
So Geht's

Dein Komponente im protected Abschnitt

Delphi-Quellcode:
   protected
     .
     procedure WMAreaInternalMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
     .
Dein Komponente im Implementations-Teil

Delphi-Quellcode:
procedure TYourDesignInteractiveComponent.WMAreaInternalMouseMove(var Message: TWMMouseMove);
begin
  inherited;
  if not(csNoStdEvents in ControlStyle)
  then begin
    FMouseScreen.x := Message.XPos;
    FMouseScreen.y := Message.YPos;
    
    if (csDesignInteractive in ControlStyle)
    then begin
      {Mach was zur Design-Time}
    end
    else begin
      {Mach was zur Run-Time}
    end;

    paint;
  end;
end;
und dann im Desing-Time Package einen Component-Editor ...

Delphi-Quellcode:

interface

  TYourCE = class(TDefaultEditor)
  public
    function GetVerb(Index:Integer):string; override;
    function GetVerbCount: Integer; override;
    procedure ExecuteVerb(Index: Integer); override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Palette', [TYourDesignInteractiveComponent]);
  RegisterComponentEditor(TYourDesignInteractiveComponent, TYourCE);
  .
end;

function TYourCE.GetVerbCount: Integer;
begin
  result := 2;
END;

function TYourCE.GetVerb(Index: Integer):STRING;
begin
  case Index of
    0 : result := 'DesignTime Interactive ON';
    1 : result := 'DesignTime Interactive OFF';
  end;
end;

procedure TYourCE.ExecuteVerb(Index: Integer);
begin
  case Index of
    0: begin
         with TYourDesignInteractiveComponent(Component) do
         begin
           ControlStyle := ControlStyle+[csDesignInteractive];
         end;
       end;
    1: begin
         with TYourDesignInteractiveComponent(Component) do
         begin
           ControlStyle := ControlStyle-[csDesignInteractive];
         end;
       end;
  end;
end;

  .
  .

end.
das wars...

Warum... Du mußt die Win-Messages direkt abfangen. Events treten zur Desing-Time nicht ein....

Edit: Falscher Fehler
“C++ is an insult to the human brain.” [Niklaus Wirth]

2B OR NOT 2B (.. THAT IS FF)
  Mit Zitat antworten Zitat