Главная страница | назад





Article #16025: Subclass the window procedure for a TForm

 Question and Answer Database

FAQ1025D.txt   Subclass the window procedure for a TForm
Category   :VCL
Platform    :All
Product    :All 32 bit  

Question:
How can I subclass the window procedure for a TForm?

Answer:
Override the WinProc procedure for the form. The following example
overrides the window procedure for the form, and responds to the
WM_CANCELMODE message, indicating that a messagebox or other dialog
box has been executed.

Example:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure WndProc (var Message: TMessage); override;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WndProc (var Message: TMessage);
begin
  if Message.Msg = WM_CANCELMODE then begin
    Form1.Caption := 'A dialog or message box has popped up';
  end else
  inherited
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Test Message');
end;


7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99