Home General

Report Image in Code

edited June 2010 in General
Hi

RB11.08 Enterprise

I believe I have found a minor glitch when creating a report in code and
loading an image from file. If you try to load a jpg or .jpeg file then you
get an error saying that there is an Unknown picture file extension (.jpg).
There are no problems loading a bmp file. The following is an extract of
the code I am using.


var lReport: TppReport;
lImage1 : TppImage;
lTitleBand : TppTitleBand;
fn : String;
begin

lReport := TppReport.Create(Self);
lReport.DataPipeline := nil;
lReport.Units := utMillimeters;
lReport.PrinterSetup.PaperName := 'A4 (210 x 297 mm) ';
lReport.PrinterSetup.MarginLeft := 15;
lReport.PrinterSetup.MarginRight := 15;
lReport.PrinterSetup.MarginTop := 10;
lReport.PrinterSetup.MarginBottom := 10;
lReport.PreviewFormSettings.WindowState := wsMaximized;
lReport.DeviceType := 'Screen';
lReport.CreateDefaultBands;
lTitleBand := TppTitleBand.Create(self);
lTitleBand.Report := lReport;
lTitleBand.Height := 60;
lImage1 := TppImage.Create(self);
lImage1.Band := lTitleBand;
lImage1.AlignHorizontal := ahCenter;
lImage1.AlignVertical := avCenter;
lImage1.MaintainAspectRatio := True;
lImage1.Stretch := True;
lImage1.Height := 25;
lImage1.Left := 0;
lImage1.Top := 0;
lImage1.Width := 78;
fn := 'C:\Data\Graphics\companylogo.bmp'; // WORKS
// fn := 'C:\Data\Graphics\companylogo.jpg'; Does not work - Unknown
picture file extension (.jpg)
// fn := 'C:\Data\Graphics\companylogo.jpeg'; Does not work - Unknown
picture file extension (.jpeg)
if FileExists(fn) then lImage1.Picture.LoadFromFile(fn);
lReport.Print;
lReport.Free;


I have got around the problem by using a bmp file but I suggest it would be
worth tidying up at some time. Also I believe it would be worth tidying up
the "Create SubReport in Code" example in rbWiki. The following code I do
not believe works as lReport.CreateDefaultBands does not create the
TitleBand. I found that I had to create the TitleBand manually (as in my
code above). I appologize if I have got it wrong!

a.. var
a.. lSubReport: TppSubReport;
a.. lReport: TppChildReport;
a.. lLabel: TppLabel;
a.. lDBText: TppDBText;
a..
a..
a.. begin
a..
a.. lSubReport := TppSubReport.Create(Self);
a..
a.. {add to the main report's detail band}
a.. lSubReport.Band := ppReport1.DetailBand;
a..
a.. {create the child report (parameters: main report) }
a.. lSubReport.CreateReport(ppReport1);
a..
a.. lReport := TppChildReport(lSubReport.Report);
a..
a.. {assign a datapipeline}
a.. lReport.DataPipeline := plCustomers;
a..
a.. {create the default set of bands}
a.. lReport.CreateDefaultBands;
a..
a.. lLabel := TppLabel.Create(Self);
a.. lLabel.Band := lReport.TitleBand;
a.. lLabel.Caption := 'Customers';
a..
a.. lLabel.Font.Name := 'Times New Roman';
a.. lLabel.Font.Size := 24;
a..
a.. lDBText := TppDBText.Create(Self);
a.. lDBText.Band := lReport.DetailBand;
a.. lDBText.DataPipeline := plCustomers;
a.. lDBText.DataField := 'CustNo';
a..
a.. lDBText.Color := clYellow;
a.. lDBText.Font.Name := 'Times New Roman';
a.. lDBText.Font.Size := 12;
a..
a..
a..
a.. end;



Regards

Tim Murfitt


Comments

This discussion has been closed.