Hi Antaeus,
I have 250 TMyQuery in My project in several forms..
i Need to Show a form Before Open and close after open in all TMyQuery.
how to intercept the events OnBeforeOpen and OnAfterOpen of all the TMy of the project?
in the TMyConnection perhaps.
some suggestion?
Handle AfterOpen and BeforeOpen for all TMyQuery in projects..
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
You can write event handlers for both events and assign these handlers to events of each TMyQuery object on initializing your application.
The assignation method may look like this:
The assignation method may look like this:
Code: Select all
procedure AssignEventHandlers(Control: TWinControl);
var
i: integer;
begin
for i := 0 to Control.ControlCount - 1 do begin
if Control.Controls[i] is TMyQuery then begin
// assign handlers
end;
if Control.Controls[i] is TWinControl then begin
AssignEventHandlers(TWinControl(Control.Controls[i]));
end;
end;
end;-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
Thank you..
Thank's Anteaus, i go to try..Antaeus wrote:You can write event handlers for both events and assign these handlers to events of each TMyQuery object on initializing your application.
The assignation method may look like this:Code: Select all
procedure AssignEventHandlers(Control: TWinControl); var i: integer; begin for i := 0 to Control.ControlCount - 1 do begin if Control.Controls[i] is TMyQuery then begin // assign handlers end; if Control.Controls[i] is TWinControl then begin AssignEventHandlers(TWinControl(Control.Controls[i])); end; end; end;
Best Regards and a good work.
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
Re: Thank you..
With its suggestion I developed the following code:
in the OnCreate Event of Each Form I call procedure
AssignEventHandlers(Self);
you suggest some modification?
Thank's,
Code: Select all
procedure TFrmMain.doClose(DataSet: TDataSet);
begin
ShowWait( False ); //Close a FormDlg
end;
procedure TFrmMain.doOpen(DataSet: TDataSet);
begin
//Open a Form Dlg
ShowWait( True, 'Comunicando com o Servidor...' );
end;
procedure TFrmMain.AssignEventHandlers(Form: TForm);
var
nCount:Integer;
begin
for nCount := 0 to (Form as TForm).ComponentCount -1 do
if (Form as TForm).Components[ nCount ] is TMyQuery then begin
((Form as TForm).Components[ nCount ] as TMyQuery).BeforeOpen := doOpen;
((Form as TForm).Components[ nCount ] as TMyQuery).AfterOpen := doClose;
end;
end;
AssignEventHandlers(Self);
you suggest some modification?
Thank's,
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
Thank you..
Thank's for good help.Antaeus wrote:This code is good, and I don't think that it should be modified.