Discussion:
Selecting a group of records in a DBCtrlGrid
(too old to reply)
Paul E. Schoen
2010-05-14 00:26:31 UTC
Permalink
I have an application (Ortmaster) that uses database and report functions to
work with test results on devices known as reclosers. I am using
QuickReports with Delphi 4 Pro to provide a way for customers to view and
print reports. But they may run several tests on a recloser, and only print
a certain subset of these. I'm using dBase III files.

I was able to do this by prepending the text in a TESTRESULT field with an
asterisk (*), and after each test I present a MessageBox which asks if the
test should be included in the report. The asterisk is added to exclude the
results from the report, and I do this with an SQL statement. There is also
a form which can be opened with a DBCtrlGrid for each of the four database
files, and the one for results is selected for only the results for a
particular recloser. But the customer would like to be able to check or
uncheck these records for the report.

One way to do this would be to add a boolean field for true/false, but I'd
rather not change the database structure. I might be able to provide a
button that will mark or unmark the TESTRESULT field of the selected record
with the asterisk, but there should be some way of presenting the records in
the DBCtrlGrid to show if they are to be included or not. I could provide
two DBCtrlGrid components so that one shows the selected items and the other
shows the deselected items, similar to the way you can select which forms
are to be autocreated in the IDE.

There are probably many ways to do this, but I want something that will be
most convenient and easy to learn for the customers, who may not be very
computer-savvy. Maybe someone has done this before, and no sense reinventing
the wheel, so to speak. Ideas appreciated.

Thanks,

Paul
www.ortmaster.com
Paul E. Schoen
2010-05-14 00:48:39 UTC
Permalink
That's actually a DBGrid (spreadsheet style) and not DBCtrlGrid..

Paul
www.ortmaster.com
Paul E. Schoen
2010-05-14 04:02:47 UTC
Permalink
I came up with a fairly good solution. I used two DBGrid components where
the first has all test results for the selected recloser, and the second
includes only those marked with a (*) in the TESTRESULT field. There is a
button for the first DBGrid that is captioned "Select", and another for the
second grid that is captioned "Deselect".

The button handlers are as follows:

procedure TfmOrtDatabase.btSelectClick(Sender: TObject);
var S: String;
begin
S := fmReclData.qRes.Fields.FieldByName('TESTRESULT').Value;
if S[1] = '*' then begin
fmReclData.qRes.Edit;
S[1] := ' ';
fmReclData.qRes.Fields.FieldByName('TESTRESULT').Value := S;
fmReclData.qRes.Refresh;
qResReport.Refresh;
end;
end;

procedure TfmOrtDatabase.btDeselectClick(Sender: TObject);
var S: String;
begin
S := qResReport.Fields.FieldByName('TESTRESULT').Value;
if S[1] <> '*' then begin
qResReport.Edit;
if S[1] = ' ' then
S[1] := '*' else
S := '*' + S;
qResReport.Fields.FieldByName('TESTRESULT').Value := S;
fmReclData.qRes.Refresh;
qResReport.Refresh;
end;
end;

The SQL is composed as follows:

with qResReport do begin
Close;
SQL.Clear;
SQL.Add( 'SELECT * FROM ORTRES' );
SQL.Add( 'WHERE RECLID = "' + fmReclData.cbReclID.Text + '"' );
SQL.Add( 'AND NOT TESTRESULT LIKE "*%" ' );
Open;
end;

Now I just need to see how the customer likes it :)

Paul
www.ortmaster.com

Loading...