Hansaplast, I think at least part of your problem is that if you set the caption in the OnPaint handler it will trigger another repaint and another call to OnPaint.
I did a simple test, and even though it's not 100% accurate, it seems that changing the caption does not trigger the onPaint event of the form itself (only a repaint of TLabel?).
Simple resizing of the form to a little bigger, triggered onPaint around 20 times, without updating the TLabel Caption.
Doing the same test, however with updating the TLabel caption, triggered it around 20 times as well.
Since it's kinda hard to measure, it all depends how steady my hand is and if I have the mouse travel the exact same direction and distance at the same speed, I'm guessing onPaint triggers about the same amount of times during a resize, with ot without changing TLabel.caption.
I tried playing with TForm.IsResizing, but that doesn't seem to be doing anything (ie. this value doesn't appear to be "true" at any time while resizing).
Example code I used - simple form, with a TLabel on it:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Label1: TLabel;
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
counter:integer;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
ShowMessage(IntToStr(counter)); // show count
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Counter:=0;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
inc(Counter);
//label1.Caption:=IntToStr(counter);
end;
end.