Recent

Author Topic: [SOLVED] Returning to original form re-initializes creation of TStringGrid  (Read 2223 times)

Adri

  • New Member
  • *
  • Posts: 23
This issue might be hard to explain: in a game I am creating the base is a TForm holding a TStringGrid (where the action is) and some labels and such. From the menu the user can select and open a new (smaller) form and next select a new grid-size. Upon returning into the main form the game restarts with this new grid-size. So far so good.  ;D

Now the user is also able to select from the menu an option to fill in some real player names instead of the default 'Player1 / Player2'. Upon returning onto the main form the game restarts with a re-initialized / created TStringGrid (and the new name(s) displayed). The new name(s) is good, the new TStringGrid not.  :(
How can such be avoided?

I can image someone needs more information being able to answer. Please do ask!
I assume I have to re-order the source code in a way that the logic is correctly applied upon calling another form and returning to the original one, but I cannot find the correct order the program is looping through the code.
« Last Edit: July 29, 2017, 04:35:11 pm by Adri »

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: Returning to original form re-initializes creation of TStringGrid
« Reply #1 on: July 26, 2017, 11:27:08 pm »
Upon returning into the main form the game restarts with this new grid-size. So far so good.
...
Upon returning onto the main form the game restarts with a re-initialized / created TStringGrid (and the new name(s) displayed). The new name(s) is good, the new TStringGrid not.
So, what's wrong with the "new TStringGrid"? You don't mention what is wrong.

Where do you re-initialize the TStringGrid again.
Some code might clear things up.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Returning to original form re-initializes creation of TStringGrid
« Reply #2 on: July 27, 2017, 10:17:13 am »
Yup. give us some code.(compilable)
Specialize a type, not a var.

Adri

  • New Member
  • *
  • Posts: 23
Re: Returning to original form re-initializes creation of TStringGrid
« Reply #3 on: July 28, 2017, 11:47:09 pm »
All,

I solved this (initiated by your remarks and ideas) by adding a boolean value "GameChanged" in the source and setting and acting upon this accordingly. The game is running good now in that aspect. When completely done I'll intent to publish it somewhere so everyone can use and improve it.
Thanks again!   :D

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 590
    • Double Dummy Solver - free download
Without seeing your code it's impossible to offer a good solution to your problem. I'm going to GUESS that  you are creating, or populating a string grid in the FormShow procedure. Using booleans like "GameChanged" seems prone to error. Perhaps you want to execute your "one-time" code in the FormCreate procedure.
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018