TQuery results.

Posted on 2001-08-01
Last Modified: 2010-04-06

I've got an application I'm working on and I need to do the following...

 function GetCustomerName(sAccNum: String): String;
   with TQuery.Create(nil) do begin
     SQL.Add('Select CustomerName from CustomerDetails where AccountNumber='''+sAccNum+'''');

so that I can simply do something like....


The problem I have is the results line.  Can someone tell me how to reference the results that I glean in this manner?  (I've tried referencing the TFields property, Fields, but there appears to be nothing in it.)


Question by:Jaymol
LVL 27

Accepted Solution

kretzschmar earned 50 total points
ID: 6340035

result := fieldByName('CustomerName').AsString;
result := fields[0].AsString;

better do a test before like

if not IsEmpty then
  result := fieldByName('CustomerName').AsString;
  result := '';

if this not solves this, then use a var instead of with ... do

oh, and just use open instead of execsql or SQL.Exec

meikl ;-)

Author Comment

ID: 6340050
Thanks Meikl.

Quite annoying that I'd already tried that and it hadn't worked!  (Only difference was the check IsEmpty.)

Thanks again,


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 92
code issue 8 153
Delphi inherited method 6 76
Delphi Firemonkey: if the Sms contain special characters it won't send it 3 43
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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