I am creating a VCL forms application with multiple forms. I have created a new form called formCreateAppointment.
I am trying to load the form via this code in a menuItem:
formCreateAppointment.Show();
I am getting this error:
E2451 Undefined symbol ‘formCreateAppointment’
Do I have to declare this form as a ‘global’ object or something similiar?
Thanks
More Info
The form ‘formCreateAppointment’ is under the Project->Options->Auto-create forms. When I use the code:
formCreateAppointment->Show();
My code will not compile and I get the following error:
E2451 Undefined symbol ‘formCreateAppointment’
When you create a new Form class in the IDE, the generated .hpp file contains a global pointer for you, eg:
It sounds like you have not
#include‘d that .hpp file into your main code, eg:If you set that Form to be Auto-Created in the Project Options, that global pointer will be automatically instantiated at program startup for you (by inserting a call to
Application->CreateForm()in your project’sWinMain()function). Otherwise, you have to instantiate it manually in your code using thenewoperator instead.Either way, the variable is a pointer. VCL objects cannot be instantiated on the stack, only the heap. You have to use the
->operator to access members of the Form object, eg:If you want to use the
.operator instead then you have to dereference the pointer first: