Recent

Author Topic: Form Resizing Lagging  (Read 4509 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Form Resizing Lagging
« on: August 17, 2021, 02:14:55 pm »
Hello :)

I have a lot of Components on my Main Form and i have a Resize Function wich works Fine but why is it Lagging so hard when i resize the Window ?

Thanks in advice

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Form Resizing Lagging
« Reply #1 on: August 17, 2021, 02:26:15 pm »
It's impossible to say without first seeing what your code is doing but, one of the usual culprits? your code triggering multiple nested paint cycles due, usually, to resizing the form/controls inside a paint event or similar "shenanigans" (with all due respect ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Form Resizing Lagging
« Reply #2 on: August 17, 2021, 02:37:04 pm »
It's impossible to say without first seeing what your code is doing but, one of the usual culprits? your code triggering multiple nested paint cycles due, usually, to resizing the form/controls inside a paint event or similar "shenanigans" (with all due respect ;)

I have a TImage which i use to paint. it will repaint the whole thing everytime the Image gets refreshed. Could i somehow block this ? i guess then the painting itslef wouldn't be the Same ? Is there a Workaround ?

blocked it with a Variable but its Still lagging... maybe bc i have Some Pictures wich get loaded every time ?.

All other Components are standard Lazarus components (Tedit, Labels, Buttons(Colored Buttons from custom Drawn Package), normal Buttons...).
Graphic performance
« Last Edit: August 17, 2021, 02:50:47 pm by Weitentaaal »

balazsszekely

  • Guest
Re: Form Resizing Lagging
« Reply #3 on: August 17, 2021, 02:53:50 pm »
@Weitentaaal

You're under windows land of unlimited possibilities :D. You can try something like this:
Code: Pascal  [Select][+][-]
  1. uses windows;
  2.  
  3. var
  4.   PrevWndProc: WNDPROC;
  5.  
  6. function WndCallback(AHWND: HWND; uMsg: UINT; wParam: WParam; lParam: LParam): LRESULT; stdcall;
  7. begin
  8.   case uMsg of
  9.     WM_ENTERSIZEMOVE:
  10.       Form1.DisableAlign;
  11.     WM_EXITSIZEMOVE:
  12.       Form1.EnableAlign;
  13.   end;
  14.   Result := CallWindowProc(PrevWndProc, Ahwnd, uMsg, WParam, LParam);
  15. end;
  16.  
  17. procedure TForm1.FormCreate(Sender: TObject);
  18. begin
  19.   PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Form1.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
  20. end;

PS: If EnableAlign/DisableAlign does not work, switch to LockWindowUpdate(Form1.Handle) and LockWindowUpdate(0) respectively.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Form Resizing Lagging
« Reply #4 on: August 17, 2021, 03:13:27 pm »
@Weitentaaal

You're under windows land of unlimited possibilities :D. You can try something like this:
Code: Pascal  [Select][+][-]
  1. uses windows;
  2.  
  3. var
  4.   PrevWndProc: WNDPROC;
  5.  
  6. function WndCallback(AHWND: HWND; uMsg: UINT; wParam: WParam; lParam: LParam): LRESULT; stdcall;
  7. begin
  8.   case uMsg of
  9.     WM_ENTERSIZEMOVE:
  10.       Form1.DisableAlign;
  11.     WM_EXITSIZEMOVE:
  12.       Form1.EnableAlign;
  13.   end;
  14.   Result := CallWindowProc(PrevWndProc, Ahwnd, uMsg, WParam, LParam);
  15. end;
  16.  
  17. procedure TForm1.FormCreate(Sender: TObject);
  18. begin
  19.   PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Form1.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
  20. end;

PS: If EnableAlign/DisableAlign does not work, switch to LockWindowUpdate(Form1.Handle) and LockWindowUpdate(0) respectively.

I Can't use Windows cuz it will cause more Problems then it would Solve

EDIT: Works but i can't use CopyFile anymore ? and writing arrays like this: [.., .., ..] does not work either(which is no problem its just a bit weird ?). there are more than 1 Copy file now wich is the right 1 ? the param names do not tell me anything  :-[.
« Last Edit: August 17, 2021, 03:34:36 pm by Weitentaaal »

balazsszekely

  • Guest
Re: Form Resizing Lagging
« Reply #5 on: August 17, 2021, 03:56:44 pm »
@Weitentaaal
Quote
I Can't use Windows cuz it will cause more Problems then it would Solve

EDIT: Works but i can't use CopyFile anymore ? and writing arrays like this: [.., .., ..] does not work either(which is no problem its just a bit weird ?). there are more than 1 Copy file now wich is the right 1 ? the param names do not tell me anything 

Windows must be first in the uses list in the interface section. If still not works(which I doubt), then FileUtil.CopyFile(...).

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Form Resizing Lagging
« Reply #6 on: August 17, 2021, 04:34:10 pm »
@getmem worked Thanks :)

So the Sequence of the units does play a Role .. got it

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Form Resizing Lagging
« Reply #7 on: August 17, 2021, 07:49:30 pm »
So the Sequence of the units does play a Role .. got it

As documented in the Free Pascal Reference Guide, Section 16.1:
Quote from: Reference Guide: Programs
The order in which the units appear is significant, it determines in which order they are initialized. Units are initialized in the same order as they appear in the uses clause. Identifiers are searched in the opposite order, i. e. when the compiler searches for an identifier, then it looks first in the last unit in the uses clause, then the last but one, and so on. This is important in case two units declare different types with the same identifier.
[Added by me: Or functions/procedures with the same name and signature]
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Form Resizing Lagging
« Reply #8 on: August 17, 2021, 08:45:29 pm »
The order of unit initialization can be counter-intuitive when you have interdependent units.
Consider a project with 3 units, a, b, c.
The .lpr uses c.
c uses b, a
b uses a
The initialization sequence will be a > b > c before the .lpr code runs.
A cursory look at unit c might indicate that b's initialization would run before a's, since it comes first in c's uses clause. However, since b uses a, a's initialization will run before b's.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Form Resizing Lagging
« Reply #9 on: August 18, 2021, 07:45:07 am »
Thanks @howardpc and @lucamar and @getmem :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: Form Resizing Lagging
« Reply #10 on: August 18, 2021, 08:58:13 am »
The order of unit initialization can be counter-intuitive when you have interdependent units.
Consider a project with 3 units, a, b, c.
The .lpr uses c.
c uses b, a
b uses a
The initialization sequence will be a > b > c before the .lpr code runs.
A cursory look at unit c might indicate that b's initialization would run before a's, since it comes first in c's uses clause. However, since b uses a, a's initialization will run before b's.

True, but for the problem that Weltentaaal experienced that is irrelevant, cause the identifier resolution inside a unit has nothing to do with the order of the initialization and is always from right to left.

furious programming

  • Hero Member
  • *****
  • Posts: 858
Re: Form Resizing Lagging
« Reply #11 on: August 24, 2021, 03:43:04 am »
I have a lot of Components on my Main Form and i have a Resize Function […]

Do not use OnResize event — use Anchor Editor and define the behavior of all components when resizing a window or parent component. It should work efficiently, and besides, you'll be able to test the anchor settings in the designer (no need to compile and run the program).
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018