Member Avatar

Hello, I have a problem with a Form (EJournalF) that is activated unexpectedly and can't find from where. If I let it be Auto_Created
in Project/Option/Font Auto_Create there are 2 instances at run-time, if it is listed in Available_Forms, only one instance is created. I have a MenyForm as Mainform and a button that state EjournalF.Show;, but EJournalF is activated and shown inspite of pressing the Meny-button. This have worked correctly since years, but I made some additions in the code and I can't figure out what made the change. This is a production program, so any helo would be appriciated!!

Recommended Answers

All 16 Replies

Does your form have an onCreate event handler? If not, add one. Then put a breakpoint in the event handler and when you hit the breakpoint check the call stack window to see what code was running when the form is created.

Alternatively, do a "Search ... Find in files" to look for TEJournalF.Create (or whatever your form class name is) in all the files in your project. Then see where the form could possibly be created.

Another thing that may be worth checking is from the Delphi menu look at Project ... Options ... Forms and see what is listed as the main form in your application.

Member Avatar

If I don't AutoCreate EJournalF, then the form is still created once, the stack says
:00633157 TEjournalF.FormCreate +$3
which I can't interpret.
There is only one instance of TEjournalF.FormCreate and that is in the OnCreate event handler. The Main form is MenyF.
I'm totally lost!

Have you searched for TEJournalF.Create rather than TEjournal.FormCreate ?

Member Avatar

TEJournalF.Create is not found in any file.

Search your project for anything that has EJournalF in it.

Also when you stop at a breakpoint in the form's onCreate event handler, step through from there (F7 or F8) and it will take you back to whatever code created the form.

Member Avatar

If I step through OnCreate I'll hit an old problem that I have struggled with for years, "Source File not Found", frxClass.pas, and the debugging process stops, and I'm not coming back to the calling procedure. I think it has to do with Fast Report and I'm trying to get rid of that product.
I have set up a first time switch in then Meny-program and set it to True when i click the menubutton and Create EJournalF at that time and don't let it be Auto_Created. But it is most annoying, so any help is very welcome!

Can you step over (F8) the call(s) to Fast Reports code, rather than tracing into them with F7?

What variable is being used to hold your form? Is it the Delphi-provided variable in the form's unit? Something like:

  EJournalF: TEJournalF;

If so, temporarily comment out that variable and re-compile. The compilation will fail at all uses of that variable, including the form creation you are trying to locate. So just comment out any/all genuine uses of the variable and compile again. Continue that process until you come across the unwanted form creation.
If this doesn't trace the problem, (one of) your genuine form creation statements must be being called when you don't expect it. So (having removed the temporary commenting out) put breakpoints on all places where you know you are creating the form and see if you get there when you don't expect to.

Member Avatar

Thanks for your involvement. I'll carry out the tests, but have to postpone for a week.

Member Avatar

Now I have cleaned up the code , removed FastReport and let the EJournalF be Auto_Created. I set a breakpoint in OnCreate and step through. Directly after OnCreate, OnActivate is called and that is my problem! I don't want the Form be activated until I press the MenyButton that state EJournalF.Show; So the question is: Who activate the form?

What is the FormStyle for the EJournalF form?What is the FormStyle for the main form?
If you are writing an MDI application the OnActivate after OnCreate is expected, and it sounds like you probably shouldn't create EJournalF until you really need it.
If you are not writing an MDI application the OnActivate is not normal there. Something must be giving the focus to EJournalF or one of its controls. Can you post the code for the OnCreate event? Also the OnPaint event handler if you have one.

Member Avatar

FormStyle is fsNormal for all forms and the form is Activated even if I remove the OnCreate event handler, so I agree, the form ought not be activated. I don't use OnPaint eighter.

Interesting problem.
What version of Delphi are you using?
Would you be able to send me the code to have a look at?

Member Avatar

Problem solved! Thank you so much for taking part in my problem!

I have 2009, XE2 and XE4 with the same problem. I stripped down the form and got rid of everything without success. Then I created a new project with a blank mainform and a second blank form and it worked as I expected. Then I added the EJournalF stripped form and it became activated without any code in the testprogram, so it had to be in the form itself. Then I compared the two forms in the .dfm files and voilà, one difference Active = True. So easy but, I wasn't aware of it. Now I can rest in peace. Hope this can help anybody else.

Glad to hear you have solved it. Well done!

One thing I don't understand though is where is that Active = True setting? Active (which I wasn't aware of till I just checked the VCL source) is a public property so doesn't appear in the object inspector. How did you set it?

Member Avatar

Sorry, my mistake, I ment Form Proporty Visible = True !
But even so, I wasn't aware.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.