delphi - Obtain data from available form to autocreated one -


i transfer data statusbar of form2 (which on list of available forms , used login purposes), statusbar on mainform (which autocreated one). if use :

procedure tmainform.formshow(sender: tobject); begin advofficestatusbar1.panels[0].text := form2.advofficestatusbar1.panels[0].text; end; 

i access violation error. . why happening? how can on this?

based on comment following occurring:

the code using login form this:

procedure login; begin   tform2.create(nil)   try     application.mainform.hide;     if showmodal = mrok       application.mainform.show     else       application.terminate;       free;   end; end; 

what happening here there implicit variable tloginform. not same auto created variable form2: tform2; sits in tform2 unit. variable freed directly after form closes.

to see mean. if delete variable called form2 application, part of code won't compile line in original post.

what have if wanted sort of thing (i have changed name of tloginform form2).

procedure login; begin   form2 := tform2.create(nil);   application.mainform.hide;   if form2.showmodal = mrok     application.mainform.show   else   begin     form2.free;     application.terminate;   end; end; 

the have free form2 when close main form. not recommend doing sort of thing though. quick fix, far better off saving text advofficestatusbar1.panels[0].text in global variable in onclose event of form2 this:

procedure tform2.formclose(sender: tobject; var action: tcloseaction); begin   g_mysavedvariable := advofficestatusbar1.panels[0].text; end; 

and loading in main form with:

procedure tmainform.formshow(sender: tobject); begin   advofficestatusbar1.panels[0].text := g_mysavedvariable; end; 

even not ideal should , running.

if looking code login form pass data between login form , main form better off looking @ question in stackoverflow (delphi login form) along answers david , cosmin. personal preference solution cosmin don't need mess dpr , there no global variables involved.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -