[SOLVED] Placholder on TMemo lazarus / 31-LCL ---------------------------------------------------------------------- pmesquita · 2021-11-08 19:48 Guys... I'm trying to modernize the ICU in my application one of the items is: PlaceHolder as in html I'm creating a canvas in TMemo to be able to write well in a primitive way because I don't usually work with it but the text is only "written" if the memo or has the focus or the mouse over it... but I have no idea what it could be... any tips.. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TMemo = class(StdCtrls.TMemo)   private     FH: String;     FSidecolor: TColor;     FSideColorWidth: Integer;     FAskForAttention: Boolean;   FCanvas: TCanvas;     procedure SetH(const AValue: String);     procedure WMPaint(var Message: TWMPaint); message WM_PAINT;     Constructor Create(AOwner: TComponent); override;     Destructor Destroy; override;    published     Property H: String  read FH   Write SetH;   end;    ...{ TMemo } Constructor TMemo.Create(AOwner: TComponent); begin  inherited Create(AOwner);  FCanvas:= Tcanvas.Create; end; Destructor TMemo.Destroy; begin  FreeAndNil(FCanvas);  inherited Destroy; End; procedure TMemo.WMPaint(var Message: TWMPaint);var  Canvas: TControlCanvas; begin  inherited;    Canvas := TControlCanvas.Create;    try      Canvas.Control := Self;      Canvas.Font.Assign(Self.Font);      Canvas.TextOut(10, 10, FH);    finally      Canvas.Free;    end; end; procedure TMemo.SetH(const AValue: String); Begin  FH:= AValue;  Invalidate; End; ---------------------------------------------------------------------- jamie · 2021-11-08 22:49 Trying to decode your message here.. From what I get I think you are having update issues ? Invalidate is a late comer but if you use Repaint after a change it may update sooner for you. ---------------------------------------------------------------------- pmesquita · 2021-11-08 23:19 Hello, I've attached a small example of the code I posted... I tried using repaint but the problem persists... the text is only displayed if the focus is on the memo or the mouse goes over it... FPC: 3.2.2 Lazarus: 2.0.12 ---------------------------------------------------------------------- jamie · 2021-11-09 01:01 Please look at this source directly here. Its your original but I have added a delayed message because when the OS WM_Paint returns it processes the DefaultWindowProc which is when the memo updates if it needs updating.  Your attempt was correct but out of sync with how windows processes Memos and how the WM_PAINT handler is done..  I suppose you can call the defaultWindowPRoc within your code then do your canvas code afterwards and return the message as being handled but what I have here should work across the pond ... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Windows,Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,LMessages,lclType,lclintf; type   { TForm1 } TMemo = class(StdCtrls.TMemo)   private     FH: String;     FSidecolor: TColor;     FSideColorWidth: Integer;     FAskForAttention: Boolean;   FCanvas: TCanvas;     procedure SetH(const AValue: String);     procedure WMPaint(var Message: TWMPaint); message WM_PAINT;     procedure Paint(Var Msssage); message LM_USER+1;     Constructor Create(AOwner: TComponent); override;     Destructor Destroy; override;    published     Property H: String  read FH   Write SetH;   end;  TForm1 = class(TForm)    Edit1: TEdit;    Memo1: TMemo;    procedure Edit1Change(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 }procedure TMemo.Paint(Var Msssage);Var  C:TControlCanvas;Begin     C := TControlCanvas.Create;    try      C.Control := Self;      C.Font.Assign(Self.Font);      C.TextOut(10, 10, FH);    finally      C.Free;    end;end; procedure TForm1.Edit1Change(Sender: TObject);begin  memo1.H:=Edit1.Text;end; Constructor TMemo.Create(AOwner: TComponent); begin  inherited Create(AOwner);  FCanvas:= Tcanvas.Create; end; Destructor TMemo.Destroy; begin  FreeAndNil(FCanvas);  inherited Destroy; End; procedure TMemo.WMPaint(var Message: TWMPaint); begin  inherited;  PostMessage(Self.Handle,WM_USER+1, 0,0); //Post a later message... end; procedure TMemo.SetH(const AValue: String); Begin  FH:= AValue;  Invalidate; End;end. ---------------------------------------------------------------------- pmesquita · 2021-11-09 12:55 Jamie... Thank you very much for the help and explanations and with this I was able to do what I needed... Attached is an example and a little improved... Long live Lazarus/FPC