jrodenhi
2007-11-30 07:20:17 UTC
I am working on a reporting application. I would like to enable my
users to retrieve data with one or more SQL queries and store that
data in one or more ClientDatasets. So the fields will be determined
at runtime. Then I want to either use that data in FastReports or use
it in other forms of output like PDF forms. I'm getting tripped up by
what is probably a dumb problem. Here's my code:
procedure TfrmQuery.LoadDataset(iNdx: Integer; sSQL: String);{$O-}
var iField: Integer;
sArray: TStrArray;
begin
Query.SQL.Clear;
Query.SQL.Add(sSQL);
Query.Open;
if iNdx > High(Datasets) then SetLength(Datasets, Succ(iNdx));
if Datasets[iNdx] = nil then Datasets[iNdx] :=
TClientDataSet.Create(nil);
Datasets[iNdx].Name := 'Dataset' + IntToStr(iNdx);
CreateDatasetFields(Query, Datasets[iNdx]);
while not Query.Eof do begin
Datasets[iNdx].Append;
for iField := 0 to Datasets[iNdx].FieldCount - 1 do begin
Datasets[iNdx].Fields[iField].Assign(Query.Fields[iField]);
end;
Datasets[iNdx].Post;
Query.Next;
end;
sArray := CArray(Datasets[iNdx]);
end;
CArray is utility routine that copies a ClientDataset into a string
array for debugging. My problem is that, at the end of this routine,
sArray looks like
('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '') and if I try to write the
ClientDataset to a string grid, I get nothing.
So what I want to do is to fill a ClientDataset from an arbitrary
query and disconnect from the database to work with the data. Any
thoughts on what is wrong with this code?
Thanks for your help.
-Jack
users to retrieve data with one or more SQL queries and store that
data in one or more ClientDatasets. So the fields will be determined
at runtime. Then I want to either use that data in FastReports or use
it in other forms of output like PDF forms. I'm getting tripped up by
what is probably a dumb problem. Here's my code:
procedure TfrmQuery.LoadDataset(iNdx: Integer; sSQL: String);{$O-}
var iField: Integer;
sArray: TStrArray;
begin
Query.SQL.Clear;
Query.SQL.Add(sSQL);
Query.Open;
if iNdx > High(Datasets) then SetLength(Datasets, Succ(iNdx));
if Datasets[iNdx] = nil then Datasets[iNdx] :=
TClientDataSet.Create(nil);
Datasets[iNdx].Name := 'Dataset' + IntToStr(iNdx);
CreateDatasetFields(Query, Datasets[iNdx]);
while not Query.Eof do begin
Datasets[iNdx].Append;
for iField := 0 to Datasets[iNdx].FieldCount - 1 do begin
Datasets[iNdx].Fields[iField].Assign(Query.Fields[iField]);
end;
Datasets[iNdx].Post;
Query.Next;
end;
sArray := CArray(Datasets[iNdx]);
end;
CArray is utility routine that copies a ClientDataset into a string
array for debugging. My problem is that, at the end of this routine,
sArray looks like
('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '') and if I try to write the
ClientDataset to a string grid, I get nothing.
So what I want to do is to fill a ClientDataset from an arbitrary
query and disconnect from the database to work with the data. Any
thoughts on what is wrong with this code?
Thanks for your help.
-Jack