Hi All -
Can anyone tell me if there is a way to quickly build a default report
layout given a DataSet. I would like to accomplish this at run-time and
present my user with a report on a dataset whose structure is unknown.
Thanks.
Louis Kleiman
SSTMS, Inc.
Comments
memo on a form and created a query on my data. Then I took the field names
and created labels in the header and dbtexts in the detail band. You'll
want to measure the with of these and create components up until the end of
the page width. Then you'll need to wrap the controls to the next line if
you still have controls to create from the dataset. Our report wizard code
works similarly, and as a registered user you have access to this source
code. Look in ppRptWiz.pas.
procedure TForm1.Button2Click(Sender: TObject);
begin
BuildQuery;
ppReport1.Print;
end;
procedure TForm1.BuildQuery;
begin
Query1.Active := False;
Query1.SQL.Assign(Memo1.Lines);
Query1.Active := True;
CreateReportComponents;
end;
procedure TForm1.CreateReportComponents;
var
lFieldNames: TStrings;
lLabel: TppLabel;
lDBText: TppDBText;
ldLeft: Double;
liIndex: Integer;
begin
lFieldNames := TStringList.Create;
Query1.GetFieldNames(lFieldNames);
ldLeft := 0.5;
for liIndex := 0 to lFieldNames.Count - 1 do
begin
{need to create a TppLabel in header band and TppDBText in detail
band}
lLabel := TppLabel.Create(ppReport1);
lLabel.AutoSize := False;
lLabel.Width := 0.75;
lLabel.Caption := lFieldNames[liIndex];
lLabel.Band := ppHeaderBand1;
lLabel.Left := ldLeft;
lLabel.Top := 0.25;
lLabel.Font.Size := 8;
lLabel.Font.Color := clBlack;
lLabel.Font.Name := 'Arial';
lLabel.Color := clYellow;
lDBText := TppDBText.Create(ppReport1);
lDBText.Width := lLabel.Width;
lDBText.DataField := lFieldNames[liIndex];
lDBText.DataPipeline := ppDBPipeline1;
lDBText.Band := ppDetailBand1;
lDBText.Font.Size := 8;
lDBText.Font.Color := clBlack;
lDBText.Font.Name := 'Arial';
lDBText.Left := ldLeft;
lDBText.Top := 0.5;
lDBText.Height := 0.5;
lDBText.WordWrap := True;
lDBText.AutoSize := True;
ldLeft := ldLeft + 0.80;
end;
lFieldNames.Free;
end;
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com