 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Graham Guest
|
Posted: Thu Apr 26, 2007 1:41 pm Post subject: Buttons to change SQL in ADOQuery |
|
|
I would like to be able to click on a set of small buttons captioned A, B, C
etc, to change the SQL statement of an ADOQuery. in Delphi 6. The SQL
refers to an Access table called HomeAd, and the buttons should filter out
records where the Surname field begins with A,B,C etc.
This shows what I have done:
procedure TfmHomeAddMain.btnAClick(Sender: TObject);
begin
with HomeQuery do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM HomeAd');
if Sender = btnA then
SQL.Append('WHERE Surname LIKE''A%''');
Open;
end;
end;
If I use a Parameter, I think it would have to take the whole of the surname
field, not just the first letter?. There is a calculated field which
displays the first latter, but it is not in the underlying dataset.
Is there some simple way to repeat the above procedure without having one
for each of 26 buttons? I thought of a case statemetn, but it needs an
integer in case xxx of, I can't see how to use Sender here.
Can anyone advise please?
Graham. |
|
| Back to top |
|
 |
Chris.Cheney Guest
|
Posted: Thu Apr 26, 2007 3:15 pm Post subject: Re: Buttons to change SQL in ADOQuery |
|
|
"Graham" <print (AT) jedpress (DOT) co.uk> wrote in
news:4630659d (AT) newsgroups (DOT) borland.com:
| Quote: | I would like to be able to click on a set of small buttons captioned
A, B, C etc, to change the SQL statement of an ADOQuery. in Delphi 6.
The SQL refers to an Access table called HomeAd, and the buttons
should filter out records where the Surname field begins with A,B,C
etc. This shows what I have done:
procedure TfmHomeAddMain.btnAClick(Sender: TObject);
begin
with HomeQuery do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM HomeAd');
if Sender = btnA then
SQL.Append('WHERE Surname LIKE''A%''');
Open;
end;
end;
If I use a Parameter, I think it would have to take the whole of the
surname field, not just the first letter?. There is a calculated field
which displays the first latter, but it is not in the underlying
dataset.
Is there some simple way to repeat the above procedure without having
one for each of 26 buttons? I thought of a case statemetn, but it
needs an integer in case xxx of, I can't see how to use Sender here.
Can anyone advise please?
Graham.
|
Set the integer Tag field of each button to be the Ord value of each
character, e.g. btnA.Tag := Ord('A'); etc
then, in the event routine (i.e. the same routine for each button),
something like
SQL.Clear;
SQL.Add(Format('SELECT * FROM HomeAd WHERE Surname LIKE ''%s%%''',
[Char((Sender as TButton).Tag)]));
HTH |
|
| Back to top |
|
 |
Jon Purvis Guest
|
Posted: Thu Apr 26, 2007 7:00 pm Post subject: Re: Buttons to change SQL in ADOQuery |
|
|
Graham wrote:
| Quote: | I would like to be able to click on a set of small buttons captioned A, B, C
etc, to change the SQL statement of an ADOQuery. in Delphi 6. The SQL
refers to an Access table called HomeAd, and the buttons should filter out
records where the Surname field begins with A,B,C etc.
This shows what I have done:
procedure TfmHomeAddMain.btnAClick(Sender: TObject);
begin
with HomeQuery do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM HomeAd');
if Sender = btnA then
SQL.Append('WHERE Surname LIKE''A%''');
Open;
end;
end;
|
Assuming the Button caption is only a single letter, this should work.
procedure TfmHomeAddMain.btnAClick(Sender: TObject);
var TempString: string;
begin
with Sender as TButton do TempString:=Caption;
with HomeQuery do
Close;
SQL.Clear;
SQL.Add('SELECT * FROM HomeAd WHERE Surname LIKE''TempString%''');
Open;
end;
end;
--
Jon Purvis
Texas Parks and Wildlife Department
Austin, TX |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|