Solved

Generic access to different queries to the same table

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now