Contact   About
Apps for Windows Source Code SQL Server Extensions  

Flag Hint component for Delphi

Download Demo with Source Code. It is FREE!

Screenshot of the FlagHint Demo Application
Download for Free: (16KB)

Demo package includes

  • License agreement;
  • Manual in HTML file (is what you currently read);
  • Source code of the sample project;
  • FREE — full source code of the component (FlagHint.pas).
Please take also a look at the advanced commercial version of the component.

Component feature overview

The Task

When writing code to handle the dialog box inputs, it is the common practice to use WinAPI function MessageBox() to show the only information texts, such as «Numeric value is too large», «Password is incorrect», etc. When the user looks at this message then he needs a time to realize where he goes wrong (with what control), then he needs to discard the message box by pressing «OK» button using the mouse or keyboard and, finally, move the input focus to the required control.
Have you ever been tired of these repetitive actions? Is there any method to simplify this task?

The Solution

Conceptually, mcFlagHint is a combination of the Windows popup hints, «What's this?» context popup help, and our needs to quickly show and hide diagnostic messages. MCFlagHint simplifies the user's life:
  • User has no need to search the screen for the problematic control — the component will set focus to it, graphically point to it and display the message near to it.
  • User has no need to perform any special actions to discard this message from the screen. When he understand the message then he just continue with his task and the message will disappear.
  • Programmer may use only single function call, DoFlagHint, to display the message (see the Example below).

    Feature notes

  • MCFlagHint is displayed as modeless window (not modal or dialog) and can be discarded due to any user acivity (clicking mouse or pressing keyboard) excepting the mouse movements.
  • Only one MCFlagHint window can be visible at the same moment.


  • Run Delphi and start the new project.
  • Include FlagHint into the uses clause of the Unit1. Now you've got access to MCFlagHint global variable.
  • Drop TEdit onto the Form1.
  • For the Edit1.OnChange, write the following code:
    if Length(Edit1.Text) > 5 then
       DoFlagHint('The desired maximum text length is 5 chars', Edit1);
  • Run the project. Type more than 5 characters into Edit1. You should see the hint near to Edit1. Try to press any key, or click the mouse, or switch to another application. Any user activity (except the mouse movements) causes hint window to be discarded.

    FlagHint.pas Reference

    Installation note

    This component has not to be installed into the Delphi Component Palette. It can be simple copied to any appropriate project's directory.

    Variables: mcFlagHint
    Procedures: DoFlagHint
    TmcFlagHint methods: Activate, Create, Destroy, Hide, Show
    TmcFlagHint properties: Caption, ShadowSize, StickColor, StickHeight, Target, Visible


    A global variable to interact with the hint message window.

    var mcFlagHint: TmcFlagHint = nil;

    Variable is being initialized in the unit's initialization section and disposed in the finalization section.
    You can refer to this variable to adjust some properties of the component.


    Displays the hint message window with the text specified in ACaption and sets focus to the form control specified in ATarget.

    procedure DoFlagHint(ACaption: String; ATarget: TWinControl);
    [in] Message text to be displayed.
    [in] Control to be focused.
    This procedure just making call to the TmcFlagHint.Activate(). This is the preferrable way to use DoFlagHint() instead of mcFlagHint.Activate() or series of
    with mcFlagHint do begin Caption := …; Target := …; Show; end;

    TmcFlagHint, methods

    Assigns new values to the properties Caption and Target and then displays the hint message window.

    procedure Activate(ACaption: String; ATarget: TWinControl);
    [in] Message text to be displayed.
    [in] Control to be focused.
    This is the preferrable way to use Activate instead of using the series of
    with mcFlagHint do begin Caption := …; Target := …; Show; end;

    Creates an instance of TmcFlagHint class.

    constructor Create(AOwner: TComponent); override;

    You have no need to explicitly call Create: this is being done automatically in the unit's initialization section.

    Destroys an instance of TmcFlagHint class.

    destructor Destroy; override;

    Uninstalls Windows Message Hook what can be set by Show or Activate methods.
    You have no need to explicitly call Destroy: this is being done automatically during the execution of the unit's finalization section.

    Hides hint message window from the screen.

    procedure Hide;

    Similar to Visible := False;
    Uninstalls Windows Message Hook previously installed by Show.

    Displays hint message window on the screen using current values of Caption and Target properties.

    procedure Show;

    Similar to Visible := True;
    Installs Windows Message Hook to monitor the user's activity. This Hook is being active only while the hint message window is visible.
    mcFlagHint.Show might be called when there is no need to change the values of the properties Caption and Target.

    TmcFlagHint, properties

    Specifies the text of the message to be displayed. Read/Write.

    property Caption: String;

    Specifies size, in pixels, of the shadow dropped from the hint message window. Read/Write.

    property ShadowSize: Integer default 4;

    When ShadowSize is grater than StickHeight then the height of the the pointing line is adjusted before painting. Actual value of StickHeight is not modified.

    Specifies color of the stick. Read/Write.

    property StickColor: TColor default clRed;

    Specifies height, in pixels, of the pointing line from the hint message window to the focused control. Read/Write.

    property StickHeight: Integer default 12;

    See remarks for ShadowSize.

    Specifies the form control to be focused. Read/Write.

    property Target: TWinControl;

    When Target is nil then the pointing line will not be drawn and the window will be displayed at the top-left corner of the screen.

    Displays or hides the hint message window. Read/Write.

    property Visible: Boolean default False;

    It is internally uses Show and Hide.

  • Copyright © 2003-2017
    Share |