?
Solved

Generic access to different queries to the same table

Posted on 2006-10-25
4
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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 1000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

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