[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

What causes "A component <> already exists" error?

Posted on 2003-11-11
6
Medium Priority
?
239 Views
Last Modified: 2012-05-04
What causes "A component <> already exists" error?

MainFrm;

procedure TMainFrm.CallForm1Execute(Sender: TObject);
begin
  if not Assigned(Form1) then
     Form1:=TForm1.Create(application);
  Form1.Show;
end;

---------------------------------------------------------------------------------------

Form1;

procedure TForm1.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=cafree;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Form1:=nil;
end;

Usually this works but there are times that the error ("A component Form1 already exists" ) pops out ...


Thanks!
0
Comment
Question by:ttanyag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 400 total points
ID: 9729801
Hi,

I can't reproduce that error here. I have tried another way which worked well for me:

1.The calling part is the same (in your MainFrm).

2. In Form1

procedure TForm1.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  self.Release;
end;

and without Destroy event.

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 9729852
Oops, copied it in a wrong way. Sorry. Should be:

procedure TForm1.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  self.Release; // or Form1.Release;
  FreeAndNil(Form1);
end;

Regards, Geo
0
 
LVL 12

Assisted Solution

by:andrewjb
andrewjb earned 400 total points
ID: 9730401
I've had this when:

a) I'm inheriting one form from another
and
b) I've got two .dfm files called the same, and the compiler is getting confused and picking up the wrong one.

So, make sure for your form, that the xxx.dfm file only exists in one place, and that you haven't got two units with the same name somehow.


Andrew.
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 400 total points
ID: 9732858
just to say,
that it is bad practice to use a reference-var
in its own methods

action := caFree; //is ok -> calls internal Release

>the error ("A component Form1 already exists" )
that you get this may caused by a too short create-call after the release,
because release sends a message to itself, and it could be,
that this message is not arrived, when you try to create the form new

i myself prefere to lookup the screen.forms-list for evaluating,
if a form is already there, rather than a test of nil to the reference-var

meikl ;-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

656 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