Discussion:
Question about Init?
(too old to reply)
James5950
2008-05-15 09:27:08 UTC
Permalink
Dear All,

My program need runtime create some object, which event for these codes
process?
for example:
MemoryStream = new TMemoryStream;
Should I put this code under OnCreate or OnShow or any else?

Thanks for any comments and help
Best regards,
James
Bruce Salzman
2008-05-15 14:25:47 UTC
Permalink
Post by James5950
Dear All,
My program need runtime create some object, which event for these codes
process?
MemoryStream = new TMemoryStream;
Should I put this code under OnCreate or OnShow or any else?
Don't use the OnCreate event, it can happen before the object it is sent to
has been constructed. Note that the OnShow event can be triggered more than
once.

For an object that needs to persist for the life of a form, create that
object in the form's constructor (and delete it in the destructor). If the
object is needed only for the length of a procedure, it can be created,
used, and deleted in that procedure.
--
Bruce
Loading...