Recent

Author Topic: Progress Bar when Main Form Creation  (Read 2574 times)

runs

  • New Member
  • *
  • Posts: 26
Progress Bar when Main Form Creation
« on: February 22, 2018, 11:36:31 am »
I want a progress bar (database calcs) when main form is being created.

I've try:

Code: Pascal  [Select][+][-]
  1.   Screen.Cursor:= crHourglass;
  2.   Application.ShowMainForm:= False;
  3.   //The progress bar to show the database creation or load:
  4.   FrmPrgBar:= TFrmPrgBar.Create(Application);
  5.   FrmPrgBar.ShowOnTop;
  6.   Application.ShowMainForm:= True; //next created Form will be the Main Form
  7.   Application.CreateForm(TFrmMain, FrmMain);
  8.   FrmPrgBar.Close; //Close the progressbar
  9.   Screen.Cursor:= crDefault;
  10.   Application.Run;  

But access violation errors when  I try to access to FrmPrg inside FrmMain:

Code: Pascal  [Select][+][-]
  1. FrmPrgBar.PrgBar.StepIt;

Any suggestion?

« Last Edit: February 22, 2018, 11:38:23 am by runs »
Projects: LibreStaff

WooBean

  • Full Member
  • ***
  • Posts: 230
Re: Progress Bar when Main Form Creation
« Reply #1 on: February 22, 2018, 12:29:27 pm »
I want a progress bar (database calcs) when main form is being created.

I've try:

Code: Pascal  [Select][+][-]
  1.  ...
  2.   Application.CreateForm(TFrmMain, FrmMain);
  3.  ...
  4.   Application.Run;  

But access violation errors when  I try to access to FrmPrg inside FrmMain:

Code: Pascal  [Select][+][-]
  1. FrmPrgBar.PrgBar.StepIt;

Any suggestion?



Normally any LCL project source contains a sequence as below:
Code: Pascal  [Select][+][-]
  1.   Application.Initialize; //this one seems to be missing in your code
  2.   Application.CreateForm(TForm1, Form1);
  3.   Application.Run;
  4.  

Where have you got your "Application.Initialize;" line of code ?
« Last Edit: February 22, 2018, 12:35:39 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: Progress Bar when Main Form Creation
« Reply #2 on: February 22, 2018, 12:46:15 pm »
@runs

If it is on mainform, usually you can solve the error by moving the code to TForm.OnShow event.

runs

  • New Member
  • *
  • Posts: 26
Re: Progress Bar when Main Form Creation
« Reply #3 on: February 22, 2018, 12:51:37 pm »
Code: Pascal  [Select][+][-]
  1.  
  2. Application.Initialize;  
  3. with TFrmPrgBar.Create(nil) do
  4.         try
  5.         Show;
  6.         Application.ShowMainForm:= True; //next created Form will be the Main Form
  7.         Application.CreateForm(TFrmMain, FrmMain);
  8.         finally
  9.         Free;
  10.     end;
  11.         Application.Run;  

But I get a error message when application.run:

In this line of control.inc an AccessViolation:

Code: Pascal  [Select][+][-]
  1.  GetTextMethod := TMethod(@Self.GetTextBuf);
Projects: LibreStaff

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: Progress Bar when Main Form Creation
« Reply #4 on: February 22, 2018, 12:58:12 pm »
Bugs can hide in anywhere in the project. Please provide the compilable source. Copy all the files to a new folder except: *.bak, binary and the lib folder. Compress the folder and send the zip file to the forum.

If you're not willing to publicize your project, you can write a demo that showing the issue.
« Last Edit: February 22, 2018, 01:00:11 pm by Handoko »

WooBean

  • Full Member
  • ***
  • Posts: 230
Re: Progress Bar when Main Form Creation
« Reply #5 on: February 22, 2018, 01:46:04 pm »
Code: Pascal  [Select][+][-]
  1.  
  2. Application.Initialize;  
  3. with TFrmPrgBar.Create(nil) do
  4.         try
  5.         Show;
  6.         Application.ShowMainForm:= True; //next created Form will be the Main Form
  7.         Application.CreateForm(TFrmMain, FrmMain);
  8.         finally
  9.         Free;
  10.     end;
  11.         Application.Run;  

But I get a error message when application.run:

In this line of control.inc an AccessViolation:

Code: Pascal  [Select][+][-]
  1.  GetTextMethod := TMethod(@Self.GetTextBuf);

Well, I guess that inside FrmMain.OnCreate event you (want to) call TFrmPrgBar type form but there is no way of addressing it - no variable contains its address as it was hidden by "with TFrmPrgBar.Create(nil) do".
My advice: simplier or working code = better than just invented. Use "with .. do" very very carefully. 
« Last Edit: February 22, 2018, 01:58:24 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Progress Bar when Main Form Creation
« Reply #6 on: February 22, 2018, 03:19:26 pm »
See the attached project for a working skeleton app with a progressbar splash screen.

runs

  • New Member
  • *
  • Posts: 26
Re: Progress Bar when Main Form Creation
« Reply #7 on: February 22, 2018, 09:50:07 pm »
Finally I get it working. With your tips and advices.

Thanks you all, folks!!!  :D
Projects: LibreStaff

 

TinyPortal © 2005-2018