Question

I am using Application.ActivateHint(p), where p: TPoint, to show hint on specified position. But it always shows on actual mouse coordinates on Delphi XE2.

Please look to the stack:

Main.ApplicationEventsShowHint('Hint String Here...',True,$18FB14)
:5049c644 TCustomApplicationEvents.DoShowHint + $20
:5049d043 TMultiCaster.DoShowHint + $4B
:50454a6b TApplication.ActivateHint + $213
RxDBCtrl.TRxDBGrid.MouseMove([],934,45)

On RxDBCtrl.TRxDBGrid.MouseMove I call TApplication.ActivateHint with correct screen coordinates as the parameter. But on Main.ApplicationEventsShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo) the value of HintInfo.HintPos is the same as actual mouse coordinates. The value passed as the parameter to TApplication.ActivateHint is lost.

Why this happens? How to show a hint on desired coordinates on Delphi XE2?

Thanks a lot for the help!

Was it helpful?

Solution 2

Problems were from the following method:

procedure TJvDBGrid.CMHintShow(var Msg: TCMHintShow); message CM_HINTSHOW;

And the new property of the component:

type
  TJvDBGridCellHintPosition = (gchpDefault, gchpMouse);

property CellHintPosition: TJvDBGridCellHintPosition; default gchpDefault;

To fix the issue I use the following code before call a hint:

ShowCellHint := True;
CellHintPosition := gchpDefault;

The second line is optional. But I saw very strange gchpMouse value of the CellHintPosition property on the debugger.

OTHER TIPS

I'm sure there's a way to achieve this using the default Hint control but you might want to check out TBalloonHint component which allows you to display the hint at a given position.

Here's a very easy example on how to achieve that :

var B : TBalloonHint;

procedure TForm1.FormCreate(Sender: TObject);
begin
  B := TBalloonHint.Create(Self);
  B.Style := bhsStandard;
  CustomHint := B;
end;

When the form is created we assign the BalloonHint component to the Main Form, any component that has the parentCustomHint property set to True will inherit the CustomHint.

After that you can simply call the hint at the given Screen Position like this:

B.ShowHint(Point(X,Y)); {Where X & Y are Screen Coordinates}

For simple demonstration :

  1. Create a new blank VCL project

  2. Integrate the following:

    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    var B : TBalloonHint;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Hint := 'Test';
      ShowHint := True;
      B := TBalloonHint.Create(Self);
      B.Style := bhsStandard;
      CustomHint := B;
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var P : TPoint;
    begin
      P := Point(X,Y);
      P := ClientToScreen(P);
      B.ShowHint(P);
    end;
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top