Recent

Author Topic: [SOLVED]OnShowhint with dymanic hints  (Read 351 times)

torbente

  • Sr. Member
  • ****
  • Posts: 298
    • Noso Main Page
[SOLVED]OnShowhint with dymanic hints
« on: January 17, 2021, 01:00:31 pm »
I believe i solved this issue some time ago, but i searched the forums and i do not found nothing.

I want be able to show a customized hint for a control, which may include even global variables values.For this example lets use:

Code: Pascal  [Select][+][-]
  1. MyButton:= TButton.Create(form1);
  2. MyButton.ShowHint := true;

I know i must declare a function to be called on show hint:

Code: Pascal  [Select][+][-]
  1. MyButton.OnShowHint := CheckForHint(MyButton);

and then...

Code: Pascal  [Select][+][-]
  1. Procedure CheckForHint(Sender:TObject);
  2. Begin
  3. if Sender = MyButton then
  4.    begin
  5.    // do verifications and finally
  6.    MyButton.Hint := 'This is the customized hint';
  7.    end;
  8. if Sender = AnotherControl // and so on...
  9. end;

But i got this error:
Quote
unit1.pas(37,21) Error: Incompatible types: got "untyped" expected "<procedure variable type of procedure(TObject;PHintInfo) of object;Register>

How i could solve this?
« Last Edit: January 18, 2021, 10:51:52 pm by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

wp

  • Hero Member
  • *****
  • Posts: 8099
Re: OnShowhint with dymanic hints
« Reply #1 on: January 17, 2021, 01:34:50 pm »
Code: Pascal  [Select][+][-]
  1. MyButton.OnShowHint := CheckForHint(MyButton);

This is probably supposed to be
Code: Pascal  [Select][+][-]
  1. // if you use {$mode objfpc}
  2. MyButton.OnShowHint := @CheckForHint;
  3.  
  4. // or, if you use {$mode Delphi}
  5. MyButton.OnShowHint := CheckForHint;  
  6.  
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

lucamar

  • Hero Member
  • *****
  • Posts: 3601
Re: OnShowhint with dymanic hints
« Reply #2 on: January 17, 2021, 02:41:09 pm »
Besides what wp said, there are two other problems; the first is that the signature of your procedure doesn't reflect the one of the event. Note that the event is declared as a TControlShowHintEvent, which is:
Code: Pascal  [Select][+][-]
  1. type TControlShowHintEvent = procedure(
  2.     Sender: TObject;
  3.     HintInfo: PHintInfo) of object;
so your procedure should be:
Code: Pascal  [Select][+][-]
  1. procedure CheckForHint(Sender:TObject; HintInfo: PHintInfo);

The second is that it's declared "of object", so to be compatible your procedure should be an object's method, for example:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckForHint(Sender:TObject; HintInfo: PHintInfo);
of course, with the corresponding declaration inside the form's class, in the interface section.

That's basically it. HTH!
« Last Edit: January 17, 2021, 02:43:09 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

torbente

  • Sr. Member
  • ****
  • Posts: 298
    • Noso Main Page
Re: OnShowhint with dymanic hints
« Reply #3 on: January 18, 2021, 04:16:36 am »
EDIT: Solved using onMouseEnter instead onShowHint

Ok, i did it way and everything is ok except that the assigned hint is show the next time the cursor moves over the control.
This is what is doing:

first show the current hint
then run CheckForhint procedure
And finally assigns the new hints.

So i need something like "BeforeShowHint?

Besides what wp said, there are two other problems; the first is that the signature of your procedure doesn't reflect the one of the event. Note that the event is declared as a TControlShowHintEvent, which is:
Code: Pascal  [Select][+][-]
  1. type TControlShowHintEvent = procedure(
  2.     Sender: TObject;
  3.     HintInfo: PHintInfo) of object;
so your procedure should be:
Code: Pascal  [Select][+][-]
  1. procedure CheckForHint(Sender:TObject; HintInfo: PHintInfo);

The second is that it's declared "of object", so to be compatible your procedure should be an object's method, for example:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckForHint(Sender:TObject; HintInfo: PHintInfo);
of course, with the corresponding declaration inside the form's class, in the interface section.

That's basically it. HTH!
« Last Edit: January 18, 2021, 04:32:08 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

 

TinyPortal © 2005-2018