Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Detecting in Run time if Template has image assigned in Design Time

D10.2, RB 19.04 Win10 Build 146
My client has a report that loads a template at Run time, depending on various criteria.
They also load the Logo for a TppImage at runtime to be used in the Template.

They have recently deviated from their own protocol and I need to make it possible for the program to
1. Detect if the loaded template has a design time logo already and, if so, to use it
else
2. Load the assigned logo

procedure TBillingExportDM.ppLogoImagePrint(Sender: TObject);
var
Filename: string;
begin
// Use the logos dir if it exists. Else default to using the RootDir.
if DirectoryExists(ExtractFilePath(Application.ExeName) + 'Logos') then
Filename := ExtractFilePath(Application.ExeName) + 'Logos\' +
InvoiceHeader.FieldByName('logo_filename').AsString
else
Filename := DestinationDir + 'Logos\' +
InvoiceHeader.FieldByName('logo_filename').AsString;

Assert(Assigned(ppLogoImage));
if FileExists(Filename) then
begin
if ppLogoImage.Picture = 'NONE' then this done not work but is the result I want.
ppLogoImage.Picture.LoadFromFile(Filename);
end
else
ppLogoImage.Clear;
end;

How can I achieve the desired result?
Thanks

Comments

  • Since it looks like I will get no help here, I will answer it myself.
    This is what I am going with.
    <pre><code>procedure TBillingExportDM.ppLogoImagePrint(Sender: TObject);
    var
      Filename: string;
      aStream : TMemoryStream;
      StrmSize : int64;
    begin
    try
      aStream := TMemoryStream.Create;
      ppLogoImage.Picture.SaveToStream(aStream);
      StrmSize := aStreamSize;
    
    
    Filename := ExtractFilePath(Application.ExeName) + 'Logos\' +
    InvoiceHeader.FieldByName('logo_filename').AsString;
    
    
    if FileExists(Filename) then
    begin
    if StrmSize = 0 then          //if no default logo
      ppLogoImage.Picture.LoadFromFile(Filename);
    end
    else
      ppLogoImage.Clear;  // if logo cannot be found, we go blank
    finally
      FreeAndNil(aStream );
    end;
    end;
    
  • Hi Laurence,

    RB leverages Delphi's TPicture/TGraphic architecture.

    Here's an example:

    lGraphic := ppLogoImage.Picture.Graphic;

    if (lGraphic = nil) or (lGraphic.Empty) then
    // no logo



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • Thanks Nard
Sign In or Register to comment.