Recent

Author Topic: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?  (Read 8911 times)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #15 on: July 18, 2017, 09:25:13 pm »
So, I am guessing I need to move Form4 over to the "Available Forms"???
Yes !  :)

Quote
So, like you said, when I try to run it from the menu click --- error!
you have to create the form manually.

Code: Pascal  [Select][+][-]
  1. begin
  2.   Form4 := TForm4.Create(nil); // or use any appropriate owner)
  3.   Form4.ShowModal
  4.   Form4.free; // to free resources of form4 again
  5. end;
  6.  

You might try variations on the topic. For example you could wrap this code up inside a global procedure inside your form4 unit (instead of adding the code to your form1 menu event. that way for4 will always responsible for it's own stuff.


Quote
Remember... VB6 minset is a set in cement mode  :D
The we'll have many such discussion, i'm affraid  ;D
« Last Edit: July 18, 2017, 09:27:58 pm by molly »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #16 on: July 18, 2017, 09:25:31 pm »
Okay....

So, if I move Form4 to Available forms.
How do you load it when called??

I keep getting an error.
Just want to know for future sake.

I am going to put it back to AutoCreate and move the MSGbox to Form SHow

Thanks for your patience
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

balazsszekely

  • Guest
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #17 on: July 18, 2017, 09:26:23 pm »
Only auto-create your main form. All other form should be created dynamically, like this:
Code: Pascal  [Select][+][-]
  1. uses unit4;
  2.  
  3. procedure TForm3.Button1Click(Sender: TObject);
  4. begin
  5.   Form4 := TForm4.Create(nil);
  6.   try
  7.     Form4.ShowModal;
  8.   finally
  9.     Form4.Free;
  10.   end;
  11. end;
  12.  

On create the form is not visible. Please read this: http://wiki.freepascal.org/Event_order

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #18 on: July 18, 2017, 09:27:22 pm »
So, I am guessing I need to move Form4 over to the "Available Forms"???
Yes !  :)

Quote
So, like you said, when I try to run it from the menu click --- error!
you have to create the form manually.

Code: Pascal  [Select][+][-]
  1. begin
  2. Form4 := TForm4.Create(nil); // or use any appropriate owner)
  3. For4.ShowModal
  4. Form4.free; // to free resources of form4 again
  5.  

Quote
Remember... VB6 minset is a set in cement mode  :D
The we'll have many such discussion, i'm affraid  ;D

LOL.... okay you already answered my question

Hey VB was a big deal in the day. Totally misguided way to program....  :-[
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #19 on: July 18, 2017, 09:28:56 pm »
Word of notice, getmem's code is better than mine  :)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #20 on: July 18, 2017, 09:31:17 pm »
Whew..... A VB6'er dodge a bullet there.
My world has been re-aligned!!!!
 :-[

I guess my understanding of CreateForm has been wrong!

Thanks for everyone's patience.
 ;D
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

RAW

  • Hero Member
  • *****
  • Posts: 868
« Last Edit: July 18, 2017, 09:38:57 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #22 on: July 18, 2017, 09:32:39 pm »
Only auto-create your main form. All other form should be created dynamically, like this:
Code: Pascal  [Select][+][-]
  1. uses unit4;
  2.  
  3. procedure TForm3.Button1Click(Sender: TObject);
  4. begin
  5.   Form4 := TForm4.Create(nil);
  6.   try
  7.     Form4.ShowModal;
  8.   finally
  9.     Form4.Free;
  10.   end;
  11. end;
  12.  

On create the form is not visible. Please read this: http://wiki.freepascal.org/Event_order

Thanks Molly - GetMem....  both works great!
« Last Edit: July 18, 2017, 09:35:12 pm by technipixel »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #23 on: July 18, 2017, 10:25:59 pm »
Quote
(events can be a bitch if you do not know exact order)  :)
Yes...  :)

Here is THE CURE...  :D

Yeah... there is something missing ... the OVERRIDEs ...  :D
I think you can add the PRO stuff yourself...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #24 on: July 18, 2017, 10:33:20 pm »
Quote
(events can be a bitch if you do not know exact order)  :)
Yes...  :)

Here is THE CURE...  :D

Yeah... there is something missing ... the OVERRIDEs ...  :D
I think you can add the PRO stuff yourself...

That is helpful for me... Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #25 on: July 18, 2017, 10:36:10 pm »
The 7z won't unzipp.... get an unknown error.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #26 on: July 18, 2017, 10:40:34 pm »
I've used this:
« Last Edit: July 19, 2017, 08:09:36 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #27 on: July 18, 2017, 10:46:00 pm »
THE CURE
Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, Forms, Controls, Dialogs;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Procedure FormCreate   (Sender: TObject);
  12.    Procedure FormResize   (Sender: TObject);
  13.    Procedure FormShow     (Sender: TObject);
  14.    Procedure FormActivate (Sender: TObject);
  15.    Procedure FormPaint    (Sender: TObject);
  16.  
  17.    Procedure FormCloseQuery (Sender: TObject; Var CanClose: Boolean);
  18.    Procedure FormClose      (Sender: TObject; Var CloseAction: TCloseAction);
  19.    Procedure FormDestroy    (Sender: TObject);
  20.   End;
  21.  
  22.  VAR
  23.   Form1: TForm1;
  24.   sl   : TStringlist;
  25.  
  26. Implementation
  27.  {$R *.LFM}
  28.  
  29.  
  30. Procedure TForm1.FormCreate(Sender: TObject);
  31.  Begin
  32.   sl.Add('CREATE');
  33.  End;
  34.  
  35.  
  36. Procedure TForm1.FormResize(Sender: TObject);
  37.  Begin
  38.   sl.Add('RESIZE');
  39.  End;
  40.  
  41.  
  42. Procedure TForm1.FormShow(Sender: TObject);
  43.  Begin
  44.   sl.Add('SHOW');
  45.  End;
  46.  
  47.  
  48. Procedure TForm1.FormActivate(Sender: TObject);
  49.  Begin
  50.   sl.Add('ACTIVATE');
  51.  End;
  52.  
  53.  
  54. Procedure TForm1.FormPaint(Sender: TObject);
  55.  Begin
  56.   sl.Add('PAINT');
  57.   Close;
  58.  End;
  59.  
  60.  
  61. Procedure TForm1.FormCloseQuery(Sender: TObject; Var CanClose: boolean);
  62.  Begin
  63.   sl.Add('CLOSE QUERY');
  64.  End;
  65.  
  66.  
  67. Procedure TForm1.FormClose(Sender: TObject; Var CloseAction: TCloseAction);
  68.  Begin
  69.   sl.Add('CLOSE');
  70.  End;
  71.  
  72.  
  73. Procedure TForm1.FormDestroy(Sender: TObject);
  74.  Begin
  75.   sl.Add('DESTROY');
  76.  End;
  77.  
  78.  
  79. Initialization
  80.  sl:= TStringlist.Create;
  81.  sl.Add('INITIALIZATION');
  82.  
  83. Finalization
  84.  sl.Add('FINALIZATION');
  85.  ShowMessage(sl.Text);
  86.  sl.Free;
  87. END.

LPR
Code: Pascal  [Select][+][-]
  1. PROGRAM Project1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4.  USES
  5.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  6.    cthreads,
  7.   {$ENDIF}{$ENDIF}
  8.    Interfaces,
  9.    Forms,
  10.    Unit1,
  11.    Dialogs;
  12.  
  13.   {$R *.RES}
  14.  
  15.  
  16. BEGIN
  17.   sl.Add('LPR BEGIN');
  18.  
  19.   RequireDerivedFormResource:= True;
  20.   Application.Initialize;
  21.   Application.CreateForm(TForm1, Form1);
  22.   Application.Run;
  23.  
  24.   sl.Add('LPR END');
  25. END.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #28 on: July 18, 2017, 10:52:47 pm »
Hmm... I use Stuffit which support 7z.
But, the code will work.

Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: [SOLVED] MsgBox on 4th Form Appears While Loading Main Form - Huh?
« Reply #29 on: July 19, 2017, 03:53:13 pm »
RAW's code is a good example on how to get yourself familiar with how LCL does things in what order.

It get's even more complicated when using unit initialization/finalization sections, not to mention using static class members.

Personally i prefer to use writeln's (on Windows platform you need to turn of the projects checkbox "win32 gui application", otherwise you get errors because output channel is not assigned properly), and/or use the debugger (in your specific case, from a breakpoint inside your project's .lpr file) and step through your code to see what is actually happening.

There are also other (logging) options available for Lazarus programs.

It might perhaps sound tiresome to do but, you can learn a lot from doing these kind of (relatively simple) things.

I still find myself doing so when looking at code from others and that is too mind-boggling to follow from source alone. For example: with the additions of helpers and overloading operators, things can become complicated pretty fast.

Also, as you might have noticed: it is usually much easier for those helping that you show some code, however trivial things perhaps might look/be for you. In this particular case it actually was trivial but, you simply did not know where to look.

As you said so yourself, you have a VB mindset (nothing wrong with that), so that might cause confusion on used terminology here and there but also with regards to how you look at certain things (it simply comes with the territory of having used/using another, windows oriented, programming language).

... even people with a similar background that used TP/Delphi/FPC/Lazarus all their lives can cause conflicting situations because of different views and/or believes either by their experience or lack thereof.

All i can say is, to have patience and not get too frustrated (been there, done that). Everything you can accomplish with VB can be accomplished with Lazarus/FPC. Even if that means we have to jump through hoops to get there  :D

 

TinyPortal © 2005-2018