Jump to content

How to use inherited MainForm ?


Freeman35

Recommended Posts

How to use inherited MainForm ?

I made MainForm, I added allcode what I need. My plan is, when make new project, I'll make inherited main form from T_FRM_Ced, and just add TUniMenuItem on inherited form so I'll not write or copy all other codes.

Problem is, When run project, I get this error:

An Exception has occured in application:

Access violation at address 0040A194 in module 'project_wan.exe'. Read of address 00000000

Restart application

Type
  TFRM_Main = class(T_FRM_Ced)// My master mainform
    MNU_x: TUniMenuItem;
  private    { Private declarations }
  public    { Public declarations }
  end;
function FRM_Main: TFRM_Main;

implementation
{$R *.dfm}

uses uniGUIVars, _uDM_rukn, uniGUIApplication, _uDM_Server;

function FRM_Main: TFRM_Main;
begin
  Result := TFRM_Main(_DM_rukn.GetFormInstance(TFRM_Main));
end;

initialization
  RegisterAppFormClass(TFRM_Main);
//  RegisterMainFormClass(TFRM_Main);
end.
Link to comment
Share on other sites

I attach test case.

You can see child_MainForm's "MNU_Items" has "MNU_x1" This Item added on child_MainForm. and some Items comes from master mainform.

If you run this project you will see acces voişation error. Whem remove MNU_x1 child_MainForm, then run again, project work normal. What is wrong on this project?

Thank you

 

 
 

 

 

Fatal-Error.7z

Link to comment
Share on other sites

  • Administrators
Type
  TFRM_Main = class(T_FRM_Ced)// My master mainform
    MNU_x: TUniMenuItem;
  private    { Private declarations }
  public    { Public declarations }
  end;
function FRM_Main: TFRM_Main;

implementation
{$R *.dfm}

uses uniGUIVars, _uDM_rukn, uniGUIApplication, _uDM_Server;

function FRM_Main: TFRM_Main;
begin
  Result := TFRM_Main(_DM_rukn.GetFormInstance(TFRM_Main));
end;

initialization
  RegisterAppFormClass(TFRM_Main);
//  RegisterMainFormClass(TFRM_Main);
end.

Would you mind telling us how did you create the inherited child? Manually?

It should be done from uniGUI Wizard.

Link to comment
Share on other sites

Because, statics code on "T_FRM_Ced" Menu settings for users, some infos etc.

I'm planing move a few applicaiton to web. Why I have to copy all codes to each application? for example, a few time later found bug in code or make upgrade, why I have to do this all projects? modify one file and just build other project so stabil & fast way.

This inhrited is classic pascal style. And not hard code in master form. We talked before. MainModule is okey I can not inherited it, it has unigui codes, thread etc. But  mainform not be like that?

On my test case, has just TUniMenuItems and Items thas all, no any code no any JS code

Link to comment
Share on other sites

  • Administrators

Because, statics code on "T_FRM_Ced" Menu settings for users, some infos etc.

I'm planing move a few applicaiton to web. Why I have to copy all codes to each application? for example, a few time later found bug in code or make upgrade, why I have to do this all projects? modify one file and just build other project so stabil & fast way.

This inhrited is classic pascal style. And not hard code in master form. We talked before. MainModule is okey I can not inherited it, it has unigui codes, thread etc. But  mainform not be like that?

On my test case, has just TUniMenuItems and Items thas all, no any code no any JS code

 

 

I am telling the way you created the child form wrong. You must inherit using uniGUI Wizard:

File->New->Other-UniGUI->Inheritable Items
Link to comment
Share on other sites

  • Administrators

Same project, same way. Just add normal form and inherited form. Main form has two button. first one open normal form, second button open inherited form. Inherited form has added "MNU_y1: TUniMenuItem;"

I think this mean not just for mainform problem, tuniform problem.

 

In MainForm you've manually commented the most important part of the unit:

//initialization
//  RegisterAppFormClass(TMainForm);

And you still expect it to work?

Link to comment
Share on other sites

  • Administrators

Same project, same way. Just add normal form and inherited form. Main form has two button. first one open normal form, second button open inherited form. Inherited form has added "MNU_y1: TUniMenuItem;"

I think this mean not just for mainform problem, tuniform problem.

 

You are registering the inherited child form as application MainForm. Of course, it will fail.

initialization
  RegisterAppFormClass(TChild_MainForm);
Link to comment
Share on other sites

I'm lazy so ofcourse use wizard. Yes, I'll manually remark that registerline, I wanna make mainform TChild_MainForm, but inherited from TMainForm ( type  TChild_MainForm = class(TMainForm) )

Can you sent this codes? or test case, I can not do this

Link to comment
Share on other sites

  • 1 year later...
On 8/30/2018 at 6:47 AM, Farshad Mohajeri said:

Issue is resolved I think, but this is not recommended. Instead, use inherited frames embedded in Mainform.

Any reason for this?

I having issues right now. base form have a TUniMenuItems. Add a item to the inherited form and raise AV, remove the item the AV is gone...

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...