Recent

Author Topic: [Solved] LazReport: show/hide an image depending on field value  (Read 1647 times)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
[Solved] LazReport: show/hide an image depending on field value
« on: February 14, 2023, 10:20:10 pm »
Hi, I have a report with an image called 'OFERTA' and I want to show/hide depending on the 'Oferta' field on my query.

I've added BeforePrint event, that uses a TfrReport as Sender. I use the sender as report to find the image, check if <> nil and toggle visibility.

I've debugged the code, and yes frimg.Visible is True / False depending on the value of ('Oferta' = 'T').

Despite all being ok, the image is or always visible or always hidden, depending on how it was designed the report!

Help  %)

Code: Pascal  [Select][+][-]
  1. procedure TfrmListProductos.frProductosBeforePrint(Sender: TfrReport);
  2. var
  3.   frimg: TFRPictureView = nil;
  4. begin
  5.   if Productos.FindField('bOferta') <> nil then // ok
  6.   begin
  7.     frimg:=TFRPictureView(Sender.FindObject('OFERTA')); // ok
  8.     if Assigned(frimg) then // ok
  9.     begin
  10.       frimg.Visible := (frDBDataSetProductos.DataSet.FieldByName('Oferta').AsString = 'T'); // this is ok
  11.     end;
  12.   end;
  13. end;
« Last Edit: February 15, 2023, 01:06:15 am by lainz »

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: LazReport: show/hide an image depending on field value
« Reply #1 on: February 15, 2023, 01:06:02 am »
Solved:
In the script of the image in the report, I check 'script' checkbox and add this code:

Code: Pascal  [Select][+][-]
  1. if [sqlqyProductos.Oferta] ='T' then
  2. Picture1.Visible:=True;    

That solves the problem.. :)

 

TinyPortal © 2005-2018