Page 1 of 1
Handle AfterOpen and BeforeOpen for all TMyQuery in projects..
Posted: Mon 10 Dec 2007 00:41
by eduardosic
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?
Posted: Mon 10 Dec 2007 09:00
by Antaeus
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;
Thank you..
Posted: Mon 10 Dec 2007 10:27
by eduardosic
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;
Thank's Anteaus, i go to try..
Best Regards and a good work.
Re: Thank you..
Posted: Tue 11 Dec 2007 15:17
by eduardosic
With its suggestion I developed the following code:
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;
in the OnCreate Event of Each Form I call procedure
AssignEventHandlers(Self);
you suggest some modification?
Thank's,
Posted: Wed 12 Dec 2007 09:15
by Antaeus
This code is good, and I don't think that it should be modified.
Thank you..
Posted: Wed 12 Dec 2007 10:06
by eduardosic
Antaeus wrote:This code is good, and I don't think that it should be modified.
Thank's for good help.
