procedure TInfoForm.ShowInfo( title:
string;
db: TSQLConnection;
sql: TStringList; init_val:
string );
var
csr: TCursor;
ic, cw: integer;
qry: TSQLQuery;
dsp: TDataSetProvider;
begin
if Assigned( cds )
then
cds.Free;
cds := TClientDataSet.Create(
nil );
cds.
ReadOnly := True;
cds.OnFilterRecord := FilterRecord;
cds.Filtered := False;
Caption := title;
FilterText := '
';
FilterIndex := 1;
FindText.Text := FilterText;
FValue := '
';
csr := Screen.Cursor;
try
Screen.Cursor := crSQLWait;
qry := TSQLQuery.Create(
nil );
dsp := TDataSetProvider.Create(
nil );
cds.Active := False;
qry.SQLConnection :=
db;
--> qry.SQL :=
sql;
// PROBLEM!!!!
dsp.DataSet := qry;
cds.SetProvider( dsp );
cds.Active := True;
cds.SetProvider(
nil );
dsp.Free;
qry.Free;
DataSource.DataSet := cds;
SetBestColWidth( DBGrid );
// Fit Formwidth to all Colwidths ...
cw := (DbGrid.Columns.Count-1) +16;
// +16: Scrollbar
for ic := 0
to DbGrid.Columns.Count-1
do
cw := cw +DbGrid.Columns[ic].Width;
ClientWidth := cw +DbGrid.Width -DbGrid.ClientWidth;
Screen.Cursor := crHourGlass;
FindSelector.Items.Clear;
for ic := 0
to DbGrid.Columns.Count-1
do
FindSelector.Items.Add( DbGrid.Columns[ic].Title.Caption );
FindSelector.ItemIndex := 1;
Screen.Cursor := csr;
init_val := Trim( init_val );
if (Length( init_val ) > 0)
then
begin
cds.IndexFieldNames := DbGrid.Columns[0].FieldName;
if not cds.FindKey( [init_val] )
then
cds.First
end
else
begin
cds.IndexFieldNames := DbGrid.Columns[1].FieldName;
cds.First
end;
ShowModal
finally
Screen.Cursor := csr
end
end;