Detect current form of application?

Posted on 2002-04-17
Last Modified: 2010-04-04
There must be a simple solution to this...

I want to know the currently active form of my application (returned as a TForm).  The API function GetActiveWindow looks hopeful, but the HWnd it returns doesn't match any handle of forms in Delphi.  The only other way I can think of is to set a global variable in every OnActivate event of all forms.

Is there a better way?  Something like TApplication.ActiveForm would be nice!


Question by:robnorthcott
  • 2
  • 2
LVL 27

Accepted Solution

kretzschmar earned 100 total points
ID: 6947214

well don't now if this exits,
but look about the screen-properties

meikl ;-)
LVL 17

Expert Comment

ID: 6947317
Meikl is right. That's the easiest way I know.

procedure TForm1.Button1Click(Sender: TObject);
  if Screen.ActiveForm <> nil then

Regards, Geo
LVL 27

Expert Comment

ID: 6947324
thanks geo, for validation,
was'nt sure, because just from head

Author Comment

ID: 6947338
Err... thanks for that!  I noticed that myself a couple of minutes after posting the question (I knew there must be an easy way!)

LVL 17

Expert Comment

ID: 6947404
Hi meikl, my pleasure.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now