Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3799648
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:46:05+00:00 2026-05-19T13:46:05+00:00

I want to when Tform2 is created then show a message to user. I

  • 0

I want to when Tform2 is created then show a message to user.
I use this code, but not work well.

procedure TForm1.Button1Click(Sender: TObject);
var
   a:TForm2;
begin

if a=nil then
 begin
    a := TForm2.Create(Self);
    a.Show;
 end
 else
 begin
    showmessage('TForm2 is created');
 end;

end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:46:06+00:00Added an answer on May 19, 2026 at 1:46 pm

    That’s because you declare a as a local variable. Each time you enter TForm1.Button1Click this variable will be brand new and uninitialized even though there might still be a Form2. That means that the check for nil won’t even work.

    You should either:

    • Make a a global (like the Form2 global you get when you first create a form)
    • Make a part of the declaration of Form1 (you main form?) or a datamodule of other class that lives throughout your entire program.
    • Don’t use a variable at all, but check Screen.Forms to see if you got a Form2 in there.

    [edit]

    Like this:

    var
      i: Integer;
    begin
      // Check
      for i := 0 to Screen.FormCount - 1 do
      begin
        // Could use the 'is' operator too, but this checks the exact class instead
        // of descendants as well. And opposed to ClassNameIs, it will force you
        // to change the name here too if you decide to rename TForm2 to a more
        // useful name.
        if Screen.Forms[i].ClassType = TForm2 then
        begin
          ShowMessage('Form2 already exists');
          Exit;
        end;
      end;
    
      // Create and show.
      TForm2.Create(Self).Show;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to ask user to input something but not want to wait forever. There
This code is not working for me on Delphi XE: http://delphi.about.com/cs/adptips2000/a/bltip0800_5.htm procedure TForm1.FormDeactivate(Sender: TObject)
I want to add a bitmap to a TMenuItem created dynamically. With this code
Want the function to sort the table by HP but if duplicate HPs then
I want to create new instances of form(and show them) from a Thread. But
I need to use a DLL created using .NET framework. This DLL is made
want to open pdf file when a user clicks on hyperlink shown in gridview
Want to code a key pad for an calculator. What I want to make
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
First of all: this is not a duplicate of Delphi and SAPI . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.