was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

25 Visitors Online


 
...allen möglichen Komponenten ein Ereignis zuweisen?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (6):  
     


{
  This example shows how to assign a OnContextPopup event
  handler to all components at runtime using SetMethodProp().
  (Here: OnContextPopup event handler)
}

{
  Diese Beispiel zeigt, wie man mit Hilfe von SetMethodProp()
  allen Komponenten ein Ereignis (hier: OnContextPopup Ereignis)
  zur Laufzeit zuweisen kann.
}


  
private
    
{ Private declarations }
    
procedure AssignOnContextPopupEvent;
    procedure OnContextPopup(Sender: TObject; MousePos: TPoint;
     var Handled: Boolean);
  public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.dfm}

uses
  
TypInfo;

procedure TForm1.OnContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
begin
  with 
Sender as TComponent do
    
ShowMessage(Name + ' right-clicked!');
end;

procedure TForm1.AssignOnContextPopupEvent;
var
  
i: Integer;
  PropInfo: PPropInfo;
  Method: TMethod;
  PEvent: ^TContextPopupEvent;
begin
  for 
i := 0 to ComponentCount - 1 do
  begin
    
PropInfo := GetPropInfo(Components[i].ClassInfo, 'OnContextPopup');
    if (PropInfo <> niland (PropInfo^.PropType^^.Kind = tkMethod) then
    begin
      
Method := GetMethodProp(Components[i], PropInfo);
      if not Assigned(Method.Code) then
      begin
        
PEvent := @Method.Code;
        PEvent^ := OnContextPopup;
        Method.Data := Self;
        SetMethodProp(Components[i], PropInfo, Method);
      end;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
AssignOnContextPopupEvent;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners