Solved

Generic access to different queries to the same table

Posted on 2006-10-25
4
163 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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