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!!
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: ... 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…
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.
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!
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:
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.
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.
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.
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?