-2

I'd like to set some of my RadioButtons and Checkboxes true or false on start-up of my application... but when I did it in OnShow, OnActivate or OnCreate events handlers I get exceptions, and even whole form isn't painted (lack of many controls on form).

Have you got any good practice to do this?

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
  • 1
    Yes. Remove bugs in your code (by using debugger). – TLama Dec 17 '13 at 09:12
  • oncreate event may have this, but onshow event cant produce this kind of problem do you use custom drawing? if not then try to create a demo project drop couple of check boxes and set them to true on Form OnShow event if the problem will repeat then theres something wrong with your IDE if not then the problem is in the Code without which we cannot say much also next time try to paste the stack trace :) – AirWolf Dec 17 '13 at 09:17
  • And your code is ? SSCEE ? and what exactly exceptions say ? at least their type ? http://www.catb.org/~esr/faqs/smart-questions.html – Arioch 'The Dec 17 '13 at 09:29
  • I think it was TStyleBook issue. I'm new to it, sometimes make stupid mistakes – Sebastian Xawery Wiśniowiecki Dec 22 '13 at 18:11
  • @user30993174444, TStyleBook is located on the Firemonkey platform, that would be called releveant information that should be included in your original post. – Peter Feb 03 '14 at 21:31

1 Answers1

5

Which event you choose to use depends on when you want the action to execute.

  • OnCreate executes once only during the lifetime of the form.
  • OnShow executes every time the form goes from hidden to showing. Potentially it can execute many times during the lifetime of the form.
  • OnActivate executes every time the form form receives focus. Potentially it can execute many times during the lifetime of the form.

The controls that are defined in the .dfm file are all instantiated by the time each of these events fires.

So, on the face of it, of these choices, OnCreate is probably the most logical choice for initialization code. But only you can know for sure when you want this code to run.

As for the exceptions that you encounter, they are because your code contains bugs. Since we cannot see your code, you'll need to debug the code without our help.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490