Thema: Memo TextHint

Einzelnen Beitrag anzeigen

a.def
(Gast)

n/a Beiträge
 
#1

Memo TextHint

  Alt 13. Apr 2017, 13:31
Ich habe folgende Unit gefunden, um einem Memo ein Multi-Line-TextHint zu verpassen
Delphi-Quellcode:
unit classMemo;

interface

uses StdCtrls, Graphics, Messages, Classes, SysUtils, Controls;

type
 TMemo = class(StdCtrls.TMemo)
 private
  FTextHint: TStrings;
  FTextHintFont: TFont;
 protected
  FCanvas: TCanvas;
  procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
 public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
 published
  property TextHint: TStrings read FTextHint write FTextHint;
  property TextHintFont: TFont read FTextHintFont write FTextHintFont;
 end;

implementation

constructor TMemo.Create(AOwner: TComponent);
begin
 inherited;
 FTextHint := TStringList.Create;
 FCanvas := TControlCanvas.Create;
 FTextHintFont := TFont.Create;
 FTextHintFont.Color := clGrayText;
 TControlCanvas(FCanvas).Control := Self;
end;

destructor TMemo.Destroy;
begin
 FreeAndNil(FTextHintFont);
 FreeAndNil(FCanvas);
 FTextHint.Clear;
 FreeAndNil(FTextHint);

 inherited;
end;

procedure TMemo.WMPaint(var Message: TWMPaint);
var
 i: integer;
 TextHeight: integer;
begin
 inherited;

 if (Text = '') and (not Focused) then
  begin
   FCanvas.Font := FTextHintFont;
   TextHeight := FCanvas.TextHeight('yY'); // Dummy Text to determine Height

   for i := 0 to FTextHint.Count - 1 do
    FCanvas.TextOut(1, 1 + (i * TextHeight), FTextHint[i]);
  end;
end;

end.
Doch leider kennt der Compiler Memo1.TextHint.Add() nicht, wie das Beispiel eigentlich vorgibt.
Bekommt man irgendwie anders ein TextHint in ein Memo?

Quelle: http://stackoverflow.com/questions/1...nt-for-a-tmemo
  Mit Zitat antworten Zitat