Recent

Author Topic: [Solved] Program losing focus action  (Read 288 times)

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] Program losing focus action
« on: August 06, 2020, 01:04:20 am »
Is there a function in lazarus that can check if my application/program loses it focus.
A.k.a. when I switch to another program the main form must be set to fsNormal instead of fsStayOnTop
« Last Edit: August 06, 2020, 01:39:37 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Program losing focus action
« Reply #1 on: August 06, 2020, 01:15:47 am »
Next time I must search this forum first before asking a question.


Found the solution here:
https://forum.lazarus.freepascal.org/index.php/topic,9237.msg99053.html#msg99053
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Program losing focus action
« Reply #2 on: August 06, 2020, 11:26:34 am »
This is almost the solution.
But usually I have 2 forms on top.
How can I determine which form has the property fsStayOnTop so that I can reset them to that property
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

GetMem

  • Hero Member
  • *****
  • Posts: 3757
Re: Program losing focus action
« Reply #3 on: August 06, 2020, 01:29:39 pm »
Remove fsStayOnTop:
Code: Pascal  [Select][+][-]
  1. var
  2.   I: Integer;
  3. begin
  4.   for I := Screen.FormCount - 1 downto 0 do
  5.   begin
  6.     if (Screen.Forms[I].FormStyle = fsStayOnTop) then
  7.     begin
  8.       Screen.Forms[I].Tag := -1; //remember which form has fsStayOnTop
  9.       Screen.Forms[I].FormStyle := fsNormal;
  10.     end;
  11.   end;

Restore fsStayOnTop:
Code: Pascal  [Select][+][-]
  1. var
  2.   I: Integer;
  3. begin
  4.   for I := Screen.FormCount - 1 downto 0 do
  5.   begin
  6.     if (Screen.Forms[I].Tag = -1) then
  7.     begin
  8.       Screen.Forms[I].Tag := 0;
  9.       Screen.Forms[I].FormStyle := fsStayOnTop;
  10.     end;
  11.   end;  

madref

  • Hero Member
  • *****
  • Posts: 823
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Program losing focus action
« Reply #4 on: August 06, 2020, 01:39:26 pm »
Thanks.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

 

TinyPortal © 2005-2018