Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My forms are not showing 2

Status
Not open for further replies.

yomyom

Programmer
Dec 23, 2002
119
GB
I'm a Delphi4 user.
I've toggled the options menu not to create the forms automatically.
Clicking a menu choice should lead to a form showing on the screen given the following code:

TNewPatient.Create(self);

It works with delphi/demo examples but does not work with my own prog.

Please, all you who know better, tell me what I'm doing wrong because when I run the program and click the menu choice, the form dosen't show.
 
You may need something like

myform := TNewPatient.Create(self);
mtform.show; //or myform.showmodal;

lou
 
Weez is absolutely right.
You must add a code line to show it manual.
 
You also need to declare myform before you try and create it. So the following is what you want (assuming that TNewPatient is some kind of form):
Code:
procedure TForm1.Button2Click(Sender: TObject);
var
  myform: TNewPatient;  
begin
  myform := TNewPatient.Create(self);
  myform.Show;
end;

Just for your information, you can also use
Code:
 Application.CreateForm(TNewPatient, myform)
which does the same thing. Clive [infinity]
 
If you open and close the form, you might also want to make sure it doesn't exist already

if myform = nil then
myform := TNewPatient.Create(self);
myform.show;
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
bbegley,

Are you sure that [/code]if myform = nil[/code] is always a valid test to apply to the form variable [/code]myform[/code]?
Do you have any code elsewhere in your program to ensure [/code]myform[/code] is never a dangling pointer?

Tim

 
I don't know. How do you get a dangling pointer?

We do not use local variables to create forms. We use the variable from the form's unit, or object structures in which we destroy the existing form property before creating a new one. Inside each form, we include the lines
"Self.Release;" and "Self := nil;" in the formclose.

In my limited experience, I've found that creating multiple versions of forms with the same name is not very good practice.

Also if you hide a form, you probably don't want to create a new one every time the user hits a button. You just want to show the existing form.

Is our practice unsafe? Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
A dangling pointer is a pointer (eg. a form variable) that does not point to an object (eg. form) and is not nil. It is a pointer with no assigned value, it could be pointing to anywhere and if it is accessed, or worse, written to will probably cause a Genreal Protection Fault.

So ...
If your program has just started and the [/code]myform := TNewPatient.Create(self);[/code] statement has not run yet, what is the value of the [/code]myform[/code] variable?

Maybe Delphi initialises it to nil for us?

Brian, if your code is working then maybe Delphi is initialising [/code]myform[/code] to nil. Does anyone else know about this?

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top