Delphi Form Creation and Showing -
i trying create application 2 forms in delphi xe6. depending on paramstr
setting form2 may or may not shown before form1.
in quick test app both forms created before form1.show
invoked - during form2 shown or not
procedure tform1.formshow(sender: tobject); begin if paramstr(1) = 'foo' form2.fooshow; end; procedure tform2.fooshow; begin showmodal; end;
however in "real" application seeing different behaviour.
in case form1.show
being called application.createform(tform1, form1)
called. before form2 being created, causing problems form2 doesn't exist when needed.
any explanation why behaviour differ? missing setting buried somewhere in project>options
if form persisted visible
set true, shown it's created.
setting property false should resolve problem.
edit
ps: in case similar problem has main form unexpectedly show though visible
set false
. happens because default application show main form regardless of visible
property in call application.run
.
if so, following question should help: how can start delphi application hidden main form?
edit2
for sake of completeness, there couple other things cause form shown it's created. however, these aren't applicable specific question.
- any code explicitly shows form when it's created (such
oncreate
event) cause form shown. however, 1 hope such actions don't lead these kinds of questions. - an mdi child form can never hidden. @ best can minimised.
tip
the quickest way finding answer such questions little bit of debugging.
- set break-point in
formshow
method. - go compiler settings, , enable option build debug dcu's. (you'll want see vcl code.)
- rebuild , run application.
- when break-point, open call stack debug window.
- navigate call-stack looking trigger.
in case should have found following code in forms.pas
.
procedure tcustomform.docreate; begin //... if fsvisible in fformstate visible := true; //<-- trigger end;
and little more investagation on fsvisible
reveal root cause as: visible
property set true
.
that said, don't want coding way because you're creating dependencies via globals. error-prone; , little experiment shows shows 1 of many subtle things can cause problems.
rather avoid globals following changes in dpr:
begin application.initialize; showforms; end;
where showforms
implemented as:
procedure showforms; var lform1: tform1; lform2: tform2; begin application.createform(tfrom1, lform1); application.createform(tfrom2, lform2); if (paramstr(1) = 'foo') lform2.show else lform1.show; end;
if don't have dependencies between forms, above suffice. if have dependency, e.g. form2 uses form1: can explicitly pass reference after creating forms, bu before start doing them.
//define property on tform2 e.g. property mainform: tform1 read fmainform write setmainform; //immediately after creating both forms tell form2 use main form. lform2.mainform := lform1;
Comments
Post a Comment