Show the Hint of any component by code  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 13/07/99

Tip accessed 615 times

 


Use this function to show the hint of a component. Remember store the returned handle to later destroy the Hint:


  function RevealHint (Control: TControl): THintWindow;
  var
    ShortHint: string;
    AShortHint: array[0..255] of Char;
    HintPos: TPoint;
    HintBox: TRect;
  begin
    { Create the window: }
    Result := THintWindow.Create(Control);

    { Get first half of hint up to '|': }
    ShortHint := GetShortHint(Control.Hint);

    { Calculate Hint Window position & size: }
    HintPos := Control.ClientOrigin;
    Inc(HintPos.Y, Control.Height + 6);
    HintBox := Bounds(0, 0, Screen.Width, 0);
    DrawText(Result.Canvas.Handle,
        StrPCopy(AShortHint, ShortHint), -1, HintBox,
        DT_CALCRECT or DT_LEFT or DT_WORDBREAK or DT_NOPREFIX);
    OffsetRect(HintBox, HintPos.X, HintPos.Y);
    Inc(HintBox.Right, 6);
    Inc(HintBox.Bottom, 2);

    { Now show the window: }
    Result.ActivateHint(HintBox, ShortHint);
  end; {RevealHint}



A call Example:


 	var
 	  mango:THintWindow;
 	begin
 	  mango:=RevealHint(Button1);





To destroy the hint showed:


  procedure RemoveHint (var Hint: THintWindow);
  begin
    Hint.ReleaseHandle;
    Hint.Free;
    Hint := nil;
  end; {RemoveHint}



A call example:


 	RemoveHint(mango)



Where 'mango' is the handle returned by RevealHint