Frage

I'm building an application in which Im populating menus using DB. I can create menu items but im having trouble linking "On Click" event to particular forms. I have stored names of the forms classes in my DB and trying to use RTTI to bind them at runtime. Following is the snippet of my code that Im trying to run.

__fastcall TfrmMainMDI::TfrmMainMDI(TComponent *Owner)
    : TForm(Owner)
{
    // Register 2 form classes
    RegisterClass(__classid(TfrmSecurity));
    RegisterClass(__classid(TfrmPassword)); 
} 

Now when I try to run following code to call the form it gives "Access violation" error.

    TForm *frm = (TForm*)TFormClass(FindClass(formName));
    UnicodeString str = frm->Name;
    frm->Show();
War es hilfreich?

Lösung

Do this:

TForm *frm = 0;
Application->CreateForm( TFormClass(FindClass(formName)), &frm );

Then if frm is not null,

frm->Show();

Andere Tipps

TForm *frm = new TForm(this);

if( frm != NULL )
{
   frm->ShowModal();

   //or

   frm->Show();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top