Instead of creating variables ADOQuery1 , ADOQuery2 , ADOQuery3 , etc. of type TADOQuery create an array:
ADOQueries: array of TADOQuery;
Then set the number of elements in it when you know how much they will be:
SetLength(ADOQueries, NumberOfQueries);
Alternatively, if you know from the beginning how many elements there will be, you can define ADOQueries instead of a static array:
ADOQueries: array[0..7] of TADOQuery;
Now you can do
procedure TForm1.QueryChange(sqltext: String; query: Integer); begin ADOQueries[Query].Close; ADOQueries[Query].SQL.Clear; ADOQueries[Query].SQL.Add(sqltext); ADOQueries[Query].Open; end;
source share