Board index » delphi » Why is my component count incorrect?

Why is my component count incorrect?

All:

I have an application where I need to change databases occasionally. When I
do, I need to iterate over my TMySqlQuery components and Refresh them. I'm
using the following code:

procedure TdmLinkTables.RefreshAllQueries(dmTarget : TDataModule);
var
  intIndex : Integer;
  comTest  : TComponent;
begin
  For intIndex := 0 to dmTarget.ComponentCount - 1 do begin
     comTest := Components[intIndex];
     If (comTest is TMySqlQuery) then
        TMySqlQuery(comTest).refresh;
  end;
end;

I have to do this with 3 data modules. At first, I adapted the code from the
online help, which uses
    For intIndex := dmTarget.ComponentCount - 1 downto 0 do begin.
With this approach, my initial intIndex was 46 for my first data module. I
was receiving an "Index out of Bounds" error with the first attempt to
assign comTest. The data module in question consists of 21 TMySqlQuery
components, 20 TDataSource components, and 1 TmxDataSetExport component, for
42 components  Including the data module itself brings the total to 43
overall. I am not creating any components at runtime. If I were, it would be
included in ComponentCount, wouldn't it?

Any help appreciated.

TIA,

Mike

 

Re:Why is my component count incorrect?


Shouldn't that be

   comTest := dmTarget.Components[intIndex];

"Michael J. Austin" <austi...@ohsu.edu> wrote in message
news:3d651813$1@newsgroups.borland.com...

Quote
> All:

> I have an application where I need to change databases occasionally. When
I
> do, I need to iterate over my TMySqlQuery components and Refresh them. I'm
> using the following code:

> procedure TdmLinkTables.RefreshAllQueries(dmTarget : TDataModule);
> var
>   intIndex : Integer;
>   comTest  : TComponent;
> begin
>   For intIndex := 0 to dmTarget.ComponentCount - 1 do begin
>      comTest := Components[intIndex];
>      If (comTest is TMySqlQuery) then
>         TMySqlQuery(comTest).refresh;
>   end;
> end;

> I have to do this with 3 data modules. At first, I adapted the code from
the
> online help, which uses
>     For intIndex := dmTarget.ComponentCount - 1 downto 0 do begin.
> With this approach, my initial intIndex was 46 for my first data module. I
> was receiving an "Index out of Bounds" error with the first attempt to
> assign comTest. The data module in question consists of 21 TMySqlQuery
> components, 20 TDataSource components, and 1 TmxDataSetExport component,
for
> 42 components  Including the data module itself brings the total to 43
> overall. I am not creating any components at runtime. If I were, it would
be
> included in ComponentCount, wouldn't it?

> Any help appreciated.

> TIA,

> Mike

Re:Why is my component count incorrect?


Thanks, sometimes the most obvious things are the hardest to see.

Mike

Quote
"Ray Andrews" <del...@steeltoad.com> wrote in message

news:3d651e01$2@newsgroups.borland.com...
Quote
> Shouldn't that be

>    comTest := dmTarget.Components[intIndex];

> "Michael J. Austin" <austi...@ohsu.edu> wrote in message
> news:3d651813$1@newsgroups.borland.com...
> > All:

> > I have an application where I need to change databases occasionally.
When
> I
> > do, I need to iterate over my TMySqlQuery components and Refresh them.
I'm
> > using the following code:

> > procedure TdmLinkTables.RefreshAllQueries(dmTarget : TDataModule);
> > var
> >   intIndex : Integer;
> >   comTest  : TComponent;
> > begin
> >   For intIndex := 0 to dmTarget.ComponentCount - 1 do begin
> >      comTest := Components[intIndex];
> >      If (comTest is TMySqlQuery) then
> >         TMySqlQuery(comTest).refresh;
> >   end;
> > end;

> > I have to do this with 3 data modules. At first, I adapted the code from
> the
> > online help, which uses
> >     For intIndex := dmTarget.ComponentCount - 1 downto 0 do begin.
> > With this approach, my initial intIndex was 46 for my first data module.
I
> > was receiving an "Index out of Bounds" error with the first attempt to
> > assign comTest. The data module in question consists of 21 TMySqlQuery
> > components, 20 TDataSource components, and 1 TmxDataSetExport component,
> for
> > 42 components  Including the data module itself brings the total to 43
> > overall. I am not creating any components at runtime. If I were, it
would
> be
> > included in ComponentCount, wouldn't it?

> > Any help appreciated.

> > TIA,

> > Mike

Other Threads