Recent

Author Topic: FindComponent  (Read 4355 times)

DaveA

  • New Member
  • *
  • Posts: 26
FindComponent
« on: July 30, 2017, 08:03:58 pm »
How do I use FindComponent with a TfrReport?

If I try frReport1.FindComponent('Memo12'), it cannot find Memo12 even though it exists. Is there a report hierarchy and, if so, how do I determine where memo12 is in the hierarchy?

Dave

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: FindComponent
« Reply #1 on: July 30, 2017, 08:15:02 pm »
findcomponent is part of the Tcomponent ancestor class not the frReport. If I'm not mistaken you are looking for frReport's findObject method.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

paweld

  • Full Member
  • ***
  • Posts: 188
Re: FindComponent
« Reply #2 on: July 30, 2017, 10:39:22 pm »
events: OnEnterRect and OnBeginBand
Code: Pascal  [Select]
  1. procedure TForm1.frReport1BeginBand(Band: TfrBand);
  2. begin
  3.   bandname:=band.Name;
  4. end;
  5.  
  6. procedure TForm1.frReport1EnterRect(Memo: TStringList; View: TfrView);
  7. begin
  8.   if view.Name='Memo12' then
  9.   Caption:='Memo12 on band: '+bandname;
  10. end;
Best regards
paweld

DaveA

  • New Member
  • *
  • Posts: 26
Re: FindComponent
« Reply #3 on: July 31, 2017, 11:16:21 am »
Thanks for your input, guys

But I am no further forward. I had already tried FindObject but that doesn't find Memo12 either.

What I am trying to do is quite simple. I want the memo to be invisible on page 1 of the report (it displays the page number). I am placing the code to do that in the BeginPage event but I need to be able to get at the Visible property. It should be a no-brainer!

howardpc

  • Hero Member
  • *****
  • Posts: 3210
Re: FindComponent
« Reply #4 on: July 31, 2017, 11:41:13 am »
How is Memo12 created and added to your report?

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: FindComponent
« Reply #5 on: July 31, 2017, 12:17:13 pm »
in my tests frReport1.findobject works flawlessly. I have no idea what it might be wrong I'll need a small sample that demonstrates the problem so I can see what is out of synch.

PS.
Make sure that you do not use anything linux specific (cairo, pdf export etc) in that sample, if I can't open it I will not waste time trying to make it work or follow up.

PPS.
You can use the scripting abilities of memo12 to set its value to '' when the [page#] = 1.
« Last Edit: July 31, 2017, 12:22:38 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

DaveA

  • New Member
  • *
  • Posts: 26
Re: FindComponent
« Reply #6 on: July 31, 2017, 03:05:51 pm »
OK

I apologise Taazz, FindObject does work even if FindComponent doesn't. My code was:
Code: Pascal  [Select]
  1.   ThisObject := frReport1.FindObject('Memo12');
  2.   if assigned(ThisObject) and (ThisObject is TfrMemoView) then
  3.     TfrMemoView(ThisObject).Visible := (pgNo > 1)
  4.  

When the component was still visible on page 1 I thought the object had not been found. But the BeginPage event is fired for each page BEFORE the report is displayed and it appears that the Visible setting on the last page is used for display. Sigghhhh

I'll explore scripting.

DaveA

  • New Member
  • *
  • Posts: 26
Re: FindComponent
« Reply #7 on: July 31, 2017, 03:27:48 pm »
It actually gets worse. FindObject correctly returns Memo12 but explicitly setting Visible := false every time BeginPage fires still fails to hide it when the report is rendered.

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: FindComponent
« Reply #8 on: July 31, 2017, 06:41:01 pm »
It actually gets worse. FindObject correctly returns Memo12 but explicitly setting Visible := false every time BeginPage fires still fails to hide it when the report is rendered.
How about setting up memo12 like the one in attached screenshot? As far as I can test this should hide the memo in page 1.

Edt: Oops here is the shot.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

DaveA

  • New Member
  • *
  • Posts: 26
Re: FindComponent
« Reply #9 on: July 31, 2017, 07:45:02 pm »
Hi Taazz

Yes, that's how I did it in the end. I put Memo12.Visible := (Page# > 1) but maybe I could have omitted the Memo12.

Thanks for the tip about scripts.