Recent

Author Topic: Detecting if a form is Active ?  (Read 6212 times)

Josh

  • Hero Member
  • *****
  • Posts: 1274
Detecting if a form is Active ?
« on: September 27, 2016, 09:31:26 pm »
Hi,

I am trying to determine which form in a multiform has got focus;

I have a timer in each form that detects for a mouse up / down and acts upon it; only if that form is the active one ( ie the form caption is Active).
Code: [Select]
form2.mousetimertimer(sender :tobject);
begin
  IsMOuseUp:=getkeystate(vk_lbutton) and $8000=0; // detects if the mouse is up
  if ((ismmouseup) and (form2.focused)) then
  begin
    // do something
    // testing show hide button
    button1.visible:=not button1.visible;
  end;
end;
The above should if I have it correct only toggle the visibilty when form2 is active;
However it is toggling the button even when form1 is the active 1.

Is there another way to detect which form is the active one?
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Detecting if a form is Active ?
« Reply #1 on: September 27, 2016, 10:31:44 pm »
Try
Code: Pascal  [Select][+][-]
  1. Screen.ActiveForm

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: Detecting if a form is Active ?
« Reply #2 on: September 30, 2016, 12:46:44 pm »
Hi Howard

Thanks for the reply; i will experiment with that.

What I did in the meantime was to create global boolean; ie form1_is_active, and set this to true and false in the form.activate and form.deactivate events; this seems to be working.

Josh
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018