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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question regarding Delphi compiler error message.

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I'm trying to work out a set of forms for a delphi program. These are 'forms' both in the delphi sense, and the literal sense; they're intended to replace a set of paper forms currently in use by our clients.

Given that three of the forms I'm immediately working with are nearly identical to each other, I created a sort of generic 'Survey Form' page, then tried to expand on it by copying the single form elsewhere, opening and renaming the copy, and handling all the form-specific details there. For the first one I tried, I had no problems. For the second, the program compiled, but whenver I click on the button for that form on my 'main screen' (five buttons, one for each of four forms and an exit button) the compiler throws an error on me the first time I attempt to access the second form.

Actual error -
Code:
Access violation at address 0047A243 in module 'SurveySheets.exe'. Read of address 00000294.

Code that produces it -
Code:
  formSurveyInputScreenNhfe.frmInptScrnNfhe.pnlNfheQA.Visible := True;
  formSurveyInputScreenNhfe.frmInptScrnNfhe.ShowModal;
Again, the first line triggers the error, but the second will do so as well if the first is commented out.

Similar code for the non-erring form -
Code:
  formSurveyInputScreenHnhd.frmInptScrnHnhd.pnlHnhdQA.Visible := True;
  formSurveyInputScreenHnhd.frmInptScrnHnhd.ShowModal;

I know this probably isn't enough information to let anyone solve the problem, but could someone suggest where in my code I might want to start looking? Again, the code for the second form compiles - the program does start. It just throws that error on me any time I try to reference the form. (And yes, I did remember to include the form in the 'main' form's uses clause.)
 
Are you sure you renamed every instance of "Form1" to "Form2" in all of the *.pas and *.dfm and *.dpr and any other project options that list it? Oh, and deleted all *.dcu?

(I've done this sort of thing plenty of times, and this is the only thing I can think of. Though I've never gotten it to compile with an error...)
 
I've looked over everything, but I can't see anything that ought to be doing this. I finally gave up; I'm copying the components from the copied forms into a new, blank form from the original project. It means redoing some of my codework, but it'll be worth it to avoid the headaches.

Thanks for the assistance, though. I appreciate it.
 
Where is the code that causes the errors? Is it in the FormCreate of the other form?

Lee
 
You can turn a form into a reusable object which can save you some time. Select the form and from the Project menu select Add to Repository. Then you can select File, New... and you'll see your form there. The other thing to do is to reference the object "Self" in the event that the form needs to reference itself.
 
@trollacious:

The code that the error triggers on, insofar as I can tell, is in the original form that's calling the problem form.

@DjangMan:

Thanks for the advice.
 
You can often solve these kinds of problems making a flow chart, starting with your DPR. Skip all internal operations and just concentrate on all the create / destroy (free) calls. If you find any reference to an object before it is created or after it is freed, there's your bug.


Roo
Delphi Rules!
 
I created a sort of generic 'Survey Form' page, then tried to expand on it by copying the single form elsewhere, opening and renaming the copy, and handling all the form-specific details there.
Doing it that way is asking for trouble: Delphi has no way of knowing that there are originals and copies. The way to do this without using the repository is to do it from the Delphi IDE: File | Save as...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top