Sundial Service
Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:No multiple Child windows in MDI application ?
Remember that, in an MDI application that is going to support multiple instances of the same child-form, Delphi's standard behavior of creating a single global "var" pointing to the form-object, and its standard behavior of creating all the forms at startup time, will not work. Instead, all of the form-instances will simply reside somewhere on the list of forms maintained by the "Application" object, and you must locate the instance in that list when you need it. Here are a couple of routines from an application we wrote, which as it happens does not allow more than one instance of a form-class to exist (this by choice), but which does illustrate the type of work that is involved. This app used resource-strings for all messages, and has some utility-routine calls that are specific to our work, but you can see the essential idea. <snip!> { Baby-making. :-) The main form is an MDI-child application. The "MakeAnotherChild" procedure reproduces indiscriminately (ahem...), while "ActivateOrMakeChild" searches to see if a child-window of this type exists. If it does, the existing child is brought front-and-center. By design, multiple instances of child-forms are never allowed to exist. (We'd have to have multiple instances of the data-model, for one thing, and we'd confuse the hell out of users, for another...) function TMainForm.MakeAnotherChild(ofClass: TFormClass) : TForm; var f: TForm; begin Application.CreateForm(ofClass, f); if f.FormStyle <> fsMDIChild then begin { common mistake } SayStop(FmtLoadStr(M_FormNotMDIChild, [f.ClassName])); end; result := f; end; {MakeAnotherChild} function TMainForm.ActivateOrMakeChild(ofClass: TFormClass) : TForm; var n: integer; f: TForm; begin { Search for the most recently created form of the specified class } f := nil; for n := MDIChildCount - 1 downto 0 do begin if MDIChildren[n] is ofClass then begin f := MDIChildren[n]; { found it - note and break out of loop } break; end; end; if Assigned(f) then begin { found it? } F.BringToFront; { make it come to the front } if F.WindowState = wsMinimized then F.WindowState := wsNormal; { and be sure it's large enough we can see it } end else begin Application.CreateForm(ofClass, f); if f.FormStyle <> fsMDIChild then begin { common mistake } SayStop(FmtLoadStr(M_FormNotMDIChild, [f.ClassName])); end; end; result := f; end; {ActivateOrMakeChild} </snip!> Quote>Beric Slobodan wrote: > <jlawre...@pitt.edu> wrote > > if MyForm = nil then MyForm := TChildForm.Create (self) else > Thanks a lot ! > Some people told me to do this checking with function Assigned, but this > don't work : > if not Assigned(ChildForm) then ...
-------------------------------------------------------------------- Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259 mailto:i...@sundialservices.com (PGP public key available.) Quote> Why =shouldn't= it be quick and easy to keep your database online? > ChimneySweep(R): "Click click, it's fixed!" {tm} > http://www.sundialservices.com/cs3web.htm
|