Recent

Author Topic: Hints.  (Read 691 times)

seghele0

  • Full Member
  • ***
  • Posts: 222
Hints.
« on: September 11, 2024, 02:52:41 pm »
The code below works in FormCreate, so all hints on the form have these specific settings.
Is it possible to do this individually for different buttons, each with their own Hint setting.
Code: Pascal  [Select][+][-]
  1. In FormCreate:
  2.  // Making special fontsize and color for HINT
  3.  Screen.HintFont.Size:= 18;
  4.  Screen.HintFont.Style:= [fsBold];
  5.  Screen.HintFont.Color:= clYellow;
  6.  Application.HintColor:= clBlack;

wp

  • Hero Member
  • *****
  • Posts: 12368
Re: Hints.
« Reply #1 on: September 11, 2024, 03:17:09 pm »
You could try to set the specific hint properties in the OnMouseEnter event handler of these controls, and reset them in OnMouseLeave.

seghele0

  • Full Member
  • ***
  • Posts: 222
Re: Hints.
« Reply #2 on: September 11, 2024, 05:29:10 pm »
I was able to get an example, but it doesn't work yet.
I keep getting an ERROR: HintWindow identifier not found.
 :(
Hopefully someone can give me the solution

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.    Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType;
  6. type
  7.   { TMainForm }
  8.   TMainForm = class(TForm)
  9.     Button1: TButton;
  10.     Button2: TButton;
  11.     procedure FormCreate(Sender: TObject);
  12.     procedure OnHintHandler(Sender: TObject);
  13.   private
  14.   public
  15.   end;
  16. var
  17.   MainForm: TMainForm;
  18. implementation
  19. {$R *.lfm}
  20. { TMainForm }
  21.  
  22. procedure TMainForm.FormCreate(Sender: TObject);
  23. begin
  24.   Button1.Hint := 'Hint (Yellow - Black)';
  25.   Button2.Hint := 'Hint (Blue - White)';
  26.   Button1.ShowHint := True;
  27.   Button2.ShowHint := True;
  28.   Application.OnShowHint := @OnHintHandler;
  29. end;
  30.  
  31. procedure TMainForm.OnHintHandler(Sender: TObject);
  32. begin
  33.   if (HintWindow.HintControl = Button1) then
  34.   begin
  35.     Application.HintColor := clBlack;
  36.     Application.HintFont.Color := clYellow;
  37.   end
  38.   else if (HintWindow.HintControl = Button2) then
  39.   begin
  40.     Application.HintColor := clWhite;
  41.     Application.HintFont.Color := clBlue;
  42.   end;
  43. end.
  44.        

wp

  • Hero Member
  • *****
  • Posts: 12368
Re: Hints.
« Reply #3 on: September 11, 2024, 06:03:36 pm »
Not 100%, because the hint's font keeps the color of the first control hit. But at least it compiles and changes the hint's background color:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.OnHintHandler(var HintStr: string; var CanShow: Boolean;
  2.     var HintInfo: THintInfo);
  3. begin
  4.   if (HintInfo.HintControl = Button1) then
  5.   begin
  6.     Screen.HintFont.Color := clBlack;
  7.     HintInfo.HintColor := clYellow;
  8.   end
  9.   else if (HintInfo.HintControl = Button2) then
  10.   begin
  11.     Screen.HintFont.Color := clWhite;
  12.     HintInfo.HintColor := clBlue;
  13.   end;
  14. end;

seghele0

  • Full Member
  • ***
  • Posts: 222
Re: Hints.
« Reply #4 on: September 12, 2024, 10:44:23 am »
Thanks for the response.
Sorry, but it doesn't work with your code either.
I get ERROR.
 :(
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.    Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType;
  6. type
  7.   { TMainForm }
  8.   TMainForm = class(TForm)
  9.     Button1: TButton;
  10.     Button2: TButton;
  11.     procedure FormCreate(Sender: TObject);
  12.     procedure OnHintHandler(var Hintstr: string; var CanShow: Boolean);
  13.   private
  14.   public
  15.   end;
  16. var
  17.   MainForm: TMainForm;
  18.  
  19. implementation
  20. {$R *.lfm}
  21. { TMainForm }
  22.  
  23. procedure TMainForm.FormCreate(Sender: TObject);
  24. begin
  25.   Button1.Hint := 'Hint (Yellow - Black)';
  26.   Button2.Hint := 'Hint (Blue - White)';
  27.   Button1.ShowHint := True;
  28.   Button2.ShowHint := True;
  29.   Application.OnShowHint := @OnHintHandler;
  30. end;
  31.  
  32. procedure TMainForm.OnHintHandler(var Hintstr: string; var CanShow: Boolean);
  33. var
  34.    HintInfo: THintInfo;
  35. begin
  36.    if HintInfo.HintControl = Button1) then
  37.    begin
  38.        Screen.HintFont.Color := clBlack;
  39.        HintInfo.HintColor := clYellow;
  40.    end
  41.    else if (HintInfo.HintControl = Button2) then
  42.    begin
  43.       Screen.HintFont.Color := clWhite;
  44.       HintInfo.HintColor := clBlue;
  45.    end;
  46. end.      

wp

  • Hero Member
  • *****
  • Posts: 12368
Re: Hints.
« Reply #5 on: September 12, 2024, 11:14:23 am »
Look carefully at my code:
  • var HintInfo: THintInfo is not a local variable but an argument of the OnHintHandler procedure (just wrapped into a separate line)
  • The final "end;" of the procedure is missing.
  • There are some strange characters in front of some lines. Delete them so that the compiler accepts the code.
Copy & paste this into your code:
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.OnHintHandler(var Hintstr: string; var CanShow: Boolean;
  2.   var HintInfo: THintInfo);
  3. begin
  4.   if (HintInfo.HintControl = Button1) then
  5.   begin
  6.     Screen.HintFont.Color := clBlack;
  7.     HintInfo.HintColor := clYellow;
  8.   end
  9.   else if (HintInfo.HintControl = Button2) then
  10.   begin
  11.     Screen.HintFont.Color := clWhite;
  12.     HintInfo.HintColor := clBlue;
  13.   end;
  14. end;

seghele0

  • Full Member
  • ***
  • Posts: 222
Re: Hints.
« Reply #6 on: September 12, 2024, 11:38:50 am »
Sorry, sorry, but I don't get it.
I have done copy/paste of the procedure, but still ERRORS.
Would it be possible to send your full working version in a ZIP?
 :-[

rvk

  • Hero Member
  • *****
  • Posts: 6404
Re: Hints.
« Reply #7 on: September 12, 2024, 11:42:25 am »
I have done copy/paste of the procedure, but still ERRORS.
Then show your code after copy/paste.
You are doing something wrong...

(And it's best to find that in your own code so you can learn  ;) )

The OnHintHandler from Application class needs to have a certain structure/parameters.
The HintWindow is passed there as parameter. You defined it as local variable. Don't do that.

So if you show your code, we can see if you fixed that.
Also... always provide the error-text itself (which you didn't do in your last post).

seghele0

  • Full Member
  • ***
  • Posts: 222
Re: Hints.
« Reply #8 on: September 12, 2024, 11:48:40 am »
The program is attached.
Thanks already.
 ;)

wp

  • Hero Member
  • *****
  • Posts: 12368
Re: Hints.
« Reply #9 on: September 12, 2024, 11:52:14 am »
You must also adjust the procedure declaration in the interface section of the unit.

rvk

  • Hero Member
  • *****
  • Posts: 6404
Re: Hints.
« Reply #10 on: September 12, 2024, 11:52:21 am »
The program is attached.
Thanks already.
 ;)
Ok.
I see you still have a different header for the function in your class definition.
You added the HintInfo in the implementation but didn't fix it in the interface part.

So if you make the parameters in the class definition the same as below... then it should work.

And if it doesn't... the actual error message would help us (without need to actually compile your code).

seghele0

  • Full Member
  • ***
  • Posts: 222
Re: Hints.
« Reply #11 on: September 12, 2024, 12:29:35 pm »
I cleaned the lenses of my glasses.
Eureca.....
Code: Pascal  [Select][+][-]
  1.   TMainForm = class(TForm)
  2.     Button1: TButton;
  3.     Button2: TButton;
  4.     procedure FormCreate(Sender: TObject);
  5.     procedure OnHintHandler(var Hintstr: string; var CanShow: Boolean;
  6.               var HintInfo: THintInfo);    
The procedure info has been adjusted.
The application works.
A special thank you for your efforts to help me.
 :)



 

TinyPortal © 2005-2018