Solved

Generic access to different queries to the same table

Posted on 2006-10-25
4
165 Views
Last Modified: 2010-04-05
I have an mySQL database which can have up to 6 queries on a given table.

I would like to access them with a generic procedure without an if then else construct as the processing on the queries will be the same for all 6.  I need to be
able to reference the queries individually and display them simultaneously.  Right now I have

procedure ProcessQuery(CodeType)

if CodeType = "AAA" then
   begin
   queryAAA.
   queryAAA.
   queryAAA.
   end
else
if CodeType = "BBB" then
   begin
   queryBBB.
   queryBBB.
   queryBBB.
   end;

what I would like to do is something like

procedure ProcessQuery(CodeType)
begin
  queryCodeType.
  queryCodeType.
  queryCodeType.
end;

Can I do it and How Would I do it if I can?

AJ

0
Comment
Question by:ajtsoukalas
  • 2
4 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 17806492
Have you tryed:
TQuery(FindComponent('query'+CodeType));
?

Regards
0
 
LVL 11

Accepted Solution

by:
calinutz earned 250 total points
ID: 17806527
Something like...

Procedure execute(codetype:string);
begin
TQuery(FindComponent('query'+CodeType)).Active:=false;
TQuery(FindComponent('query'+CodeType)).Active:=true;
end;

(it's from the head... I do not have delphi around me to check the exact syntax but I think it's ok)
0
 
LVL 3

Assisted Solution

by:cobi100
cobi100 earned 250 total points
ID: 17808920
how about something like this:

procedure TForm1.ProcessQuery(aQuery: TQuery);
begin
  //do your stuff here...
  with aQuery do
  begin
    aQuery.Open;
    while not(aQuery.Eof) do
    begin
      // do something
      Next;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ProcessQuery(queryBBB);
  ProcessQuery(queryAAA);
end;

or maybe even add a list property to your form/datamodule like:

  public
    QueryList: TList;

and do this on create:

procedure TForm1.FormCreate(Sender: TObject);
begin
  QueryList := TList.Create;
  QueryList.Add(queryAAA);
  QueryList.Add(queryBBB);
end;

and to process:

procedure TForm1.Button2Click(Sender: TObject);
var
  i: integer;
begin
  for i:= 0 to QueryList.Count - 1 do
    ProcessQuery(QueryList[i]);
end;

and let's not forget to free the list

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(QueryList);
end;





0
 

Author Comment

by:ajtsoukalas
ID: 17838887
I like both answers
I am going to split the points
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question