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