Subject Re: [IBO] How to send component name as parameter to access IBO component's methods
Author Nando Dessena

> Trying to write a procedure which I can pass as a string the component
> handler name, so that I can prepare/execute a series of datapump
> component groups (i.e. IB_Cursor, IB_datapump, IB_dsql), one group for
> each of about 7 tables that I need to archive records, then delete.
> Another Delphi programmer suggested using FindComponent(), but it just
> doesn't quite work as in:
> with dmPVEditor do
> (findcomponent(ParameterStringNameofComponent)).prepare;
> I get an "undeclared identifier" error.

not really an IBO question; anyway:

with dmPVEditor do
(FindComponent(ParameterStringNameOfComponent) as

the trick is that the FindComponent method will return a TComponent
reference, so
you need to downcast it to get the correct pair of glasses through which
to look at the object.

If the component you are trying to downcast (with the "as" operator")
does not exist, you will receive an EInvalidCast exception. You may want
to avoid exceptions by using the "is" operator together with a hardcast,
as in:

C: TComponent;


with dmPVEditor do begin
C := FindComponent(ParameterStringNameOfComponent);
if Assigned(C) and (C is TIB_Cursor) then begin
// the component does not exist or is not of the right type.

As a final note, I would avoid passing here and there component names
altogether, if possible. Cleaner solutions may exist.