I am writing a procedure to close all adoquery created and open on a (any) form, the problem is I need to do a cast on the form to identify the components. how can I make a dynamic cast like shown in the example?
I need something like this
Procedure OpenADODataSets(Form:TForm;FormType:TClass);
...
...
(Form as FormType).ComponentCount
or
Procedure OpenADODataSets(Form:TForm;FormType:TClass);
...
...
FormType(Form).ComponentCount
this is the code.
Procedure OpenADODataSets(Form:TForm;FormType:TClass);
var
i: integer;
begin
for i:=0 to (Form as FormType).ComponentCount-1 do
if (Form as FormType).Components[i].ClassType=TADOQuery then
if not TADOQuery((Form as FormType).Components[i]).Active then
TADOQuery((Form as FormType).Components[i]).Open;
end;
UPDATE
problem solved with the answer of @Edelcom
Procedure OpenADODataSets(Form:TForm);
var
i: integer;
begin
for i:=0 to Form.ComponentCount-1 do
if Form.Components[i].ClassType=TADOQuery then
if not TADOQuery(Form.Components[i]).Active then
TADOQuery(Form.Components[i]).Open;
end;