Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Generic access to different queries to the same table

Posted on 2006-10-25
4
Medium Priority
?
170 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

Technology Partners: 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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 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