Recent

Author Topic: Trouble opening form  (Read 377 times)

Newmann

  • Jr. Member
  • **
  • Posts: 65
Trouble opening form
« on: October 04, 2024, 03:11:46 am »
I have an app with two forms:
  • the main is config settings and a control to save them
  • the second is only meant to show for one second as an indicator if the app is launched with parameters

So start the app normally - you see the main window, start it with more than two parameters, the main window is hidden, and only the second window should appear for one second to notify the user.

Problem:
If I add a button on the main form and call "Form2.Show", it works perfectly fine. As soon as I pass the parameters, I get an access violation error on the show command  :o

I tried everything I can think of - even removing the auto-create part and attempted to create form2 on the fly - same issue.
(I even tried calling the OnClick procedure for the button to emulate user input for the heck of it...no joy)

All I need to do with the window before/after it opens, is update a label on it...the only label on it...nothing wow.

Any ideas of where I might be going wrong? The app itself is working perfectly in everything else that it needs to do - just this last annoying issue I need to fix before I can "ship" it...please see the attached screenshot.
« Last Edit: October 04, 2024, 03:19:20 am by Newmann »
Lazarus 1.0.14
FPC 2.6.0
Win7 Pro 64bit/Win XP Pro 32bit

TRon

  • Hero Member
  • *****
  • Posts: 3631
Re: Trouble opening form
« Reply #1 on: October 04, 2024, 04:36:12 am »
Because no code was shared (code that is usually the culprit for the issue) I can only point to a generic tutorial about multiple forms and passing variables, here.

Even if it is not possible to share the project it is not difficult to create a small demo project that in basics does exactly what your code is doing right now so that we can have a look at it.

There are several different solutions to accomplish that what you are trying to achieve and in the end it usually turns out that none of those will match your approach and/or fit your project.
« Last Edit: October 04, 2024, 04:38:00 am by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

dseligo

  • Hero Member
  • *****
  • Posts: 1411
Re: Trouble opening form
« Reply #2 on: October 04, 2024, 10:19:36 am »
So start the app normally - you see the main window, start it with more than two parameters, the main window is hidden, and only the second window should appear for one second to notify the user.

Problem:
If I add a button on the main form and call "Form2.Show", it works perfectly fine. As soon as I pass the parameters, I get an access violation error on the show command  :o

Do you call 2nd form in OnCreate method of form1 or event earlier?
It could be that Form2 isn't created yet.
You could move form2 'up' in auto create window of project options or you could called later (when everything is created).

But, as TRon already pointed out, it is difficult to guess what is in your code.

Newmann

  • Jr. Member
  • **
  • Posts: 65
Re: Trouble opening form
« Reply #3 on: October 04, 2024, 10:34:55 am »

Do you call 2nd form in OnCreate method of form1 or event earlier? <= I leave it to auto create at startup, but I also tried doing it dynamically when needed - both had the same issue.
It could be that Form2 isn't created yet. <= this is what I suspect as well
You could move form2 'up' in auto create window of project options or you could called later (when everything is created). <= I was actually considering looking into something like this when I woke up this morning - will give it a try, thanks.

But, as TRon already pointed out, it is difficult to guess what is in your code.

I'll have to whack together another small app as demo I can upload here - but I realized that as you guys pointed out, the form might not exist properly yet, and the fact that I'm hiding my main window (all though I tested it with and without that code - no difference) might be adding fuel to the fire. I'll try the above, then I was thinking of adding a third form to act as my main/form1, make it like 1x1px, plonk it in the corner of the screen where its out of view, and have that one decide which one of the other two forms to display after a 0.25sec delay.

Buuut then again, I might be back to not only square 1, but rather square -1 cause then I'd have two forms that fail to load  %)
Lazarus 1.0.14
FPC 2.6.0
Win7 Pro 64bit/Win XP Pro 32bit

Aruna

  • Hero Member
  • *****
  • Posts: 513
Re: Trouble opening form
« Reply #4 on: October 04, 2024, 12:34:35 pm »
So start the app normally - you see the main window, start it with more than two parameters, the main window is hidden, and only the second window should appear for one second to notify the user.
The attached zip file has a fully working demo that does what you want.

PS: I have tried and failed to display the passed parameters on the second forms label, maybe someone else out there can fix this?
      The second form caption when asked to display the same parameters does work fine. Hope this will help.

Newmann

  • Jr. Member
  • **
  • Posts: 65
Re: Trouble opening form
« Reply #5 on: October 04, 2024, 01:27:28 pm »
Looks like the crashing issue is resolved - the suggestion from dseligo worked => went into the project source and set Form2 to be created before Form1 8-)

Aruna - I'll have a look at the code you posted as well, thank you for your suggestion.
Lazarus 1.0.14
FPC 2.6.0
Win7 Pro 64bit/Win XP Pro 32bit

 

TinyPortal © 2005-2018