The Unofficial Newsletter of Delphi Users - by Robert
Vivrette
A Multiline Hint Property Editor
by Grahame Marsh - gsmarsh@aol
In the 25th May issue of UNDU, Jorge Turiel showed a simple, but effective way of
obtaining multiline hints. The disadvantage of his method is that the
hint is placed in the code associated with the form and not in the component's hint
property in the object inspector. What is obviously needed is a hint property editor
that allows the hint property to have multiple lines.
So having been given the "hint" by Jorge, I have written a simple property editor. It includes a TPanel to show what the hint text currently looks like. If you want to make the editor memo to look like the hint text then you need to include the following FormCreate event handler.
procedure THintStringEditDialog.FormCreate(Sender: TObject);
var
NCM: TNonClientMetrics;
begin
with Memo do
begin
NCM.cbSize := sizeof (TNonClientMetrics);
if SystemParametersInfo (SPI_GETNONCLIENTMETRICS,
0, @NCM, 0) then
Font.Handle := CreateFontIndirect
(NCM.lfStatusFont)
else
Font.Size := 8;
Font.Color := clInfoText;
Brush.Style := bsClear;
Color := clInfoBk
end
end;
Enjoy, and thanks to Jorge for the original idea. You can download the code for this by clicking here...
unit HintProp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, DsgnIntf,
ExtCtrls, StdCtrls, ComCtrls;
type
THintStringEditDialog = class(TForm)
Bevel1: TBevel;
LineCounter: TLabel;
Memo: TRichEdit;
CancelButton: TButton;
OkButton: TButton;
ShowPanel: TPanel;
procedure MemoChange(Sender: TObject);
private
public
end;
procedure Register;
implementation
{$R *.DFM}
procedure THintStringEditDialog.MemoChange(Sender: TObject);
begin
ShowPanel.Hint := Memo.Text;
LineCounter.Caption := Format ('%d Lines', [Memo.Lines.Count])
end;
type
THintProperty = class (TStringProperty)
private
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes;
override;
end;
procedure THintProperty.Edit;
begin
with THintStringEditDialog.Create (Application) do
try
Memo.Text := GetValue;
if ShowModal = mrOk then
SetValue (Memo.Text)
finally
Free
end
end;
function THintProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog]
end;
procedure Register;
begin
RegisterPropertyEditor (TypeInfo (string), nil, 'Hint',
THintProperty)
end;
end.
//******************************************************************************
object HintStringEditDialog: THintStringEditDialog
Left = 400
Top = 131
BorderStyle = bsDialog
Caption = 'Hint string editor'
ClientHeight = 277
ClientWidth = 428
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 8
Top = 8
Width = 413
Height = 229
Shape = bsFrame
end
object LineCounter: TLabel
Left = 16
Top = 16
Width = 34
Height = 13
Caption = '0 Lines'
end
object Memo: TRichEdit
Left = 16
Top = 32
Width = 397
Height = 197
HideScrollBars = False
ScrollBars = ssBoth
TabOrder = 0
WordWrap = False
OnChange = MemoChange
end
object CancelButton: TButton
Left = 344
Top = 248
Width = 75
Height = 25
Caption = 'Cancel'
ModalResult = 2
TabOrder = 1
end
object OkButton: TButton
Left = 264
Top = 248
Width = 75
Height = 25
Caption = 'Ok'
ModalResult = 1
TabOrder = 2
end
object ShowPanel: TPanel
Left = 8
Top = 246
Width = 105
Height = 29
BevelInner = bvLowered
Caption = 'Show me'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 3
end
end