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

39 Visitors Online


 
...AfterShow, AfterCreate Ereignisse implementieren?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (78):  
     


{
  Question/Abstract:

  I often want to automatically run some code directly after the form has
  shown. If this is done in the OnShow event it gets done while the form is
  still invisible (not good if the code takes a little while to run.)
  Currently, I use a Timer with its interval property set to about 200 and
  enabled set to false. In the OnShow event I set Timer.Enabled := True and
  the first statement in the OnTimer event is Timer.Enabled := False so the
  event only runs once.

  Answer:

  Post a custom message to yourself.
  The following code shows how to trigger a AfterShow, AfterCreate event.

}

const
  
WM_AFTER_SHOW = WM_USER + 300; // custom message
  
WM_AFTER_CREATE = WM_USER + 301; // custom message
type
  
TForm1 = class(TForm)
    // OnShow event
    
procedure FormShow(Sender: TObject);
    // OnCreate event
    
procedure FormCreate(Sender: TObject);
  private
    procedure 
WmAfterShow(var Msg: TMessage); message WM_AFTER_SHOW;
    procedure WmAfterCreate(var Msg: TMessage); message WM_AFTER_CREATE;
  public
  end
;

var
  
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WmAfterShow(var Msg: TMessage);
begin
  
ShowMessage('WM_AFTER_SHOW received!');
end;

procedure TForm1.WmAfterCreate(var Msg: TMessage);
begin
  
ShowMessage('WM_AFTER_CREATE received!');
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  
// Post the custom message WM_AFTER_SHOW to our form
  
PostMessage(Self.Handle, WM_AFTER_SHOW, 0, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
// Post the custom message WM_AFTER_CREATE to our form
  
PostMessage(Self.Handle, WM_AFTER_CREATE, 0, 0);
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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