Mega Code Archive

 
Categories / Delphi / Examples
 

Create

Here's my usual solution to this problem. It relies on using an object oriented approach to the options themselves. Create a class, say, TOptions, which contains fields for the various options. Define a class method called MakeCopy, e.g., procedure TOptions.MakeCopy(Copy: TOptions); begin Field1 := Copy.Field1; Field2 := Copy.Field2; etc. end; TOptionsForm should contain a public field called Options, i.e., public Options: TOptions; Then, in the main body of the program, write var Original, Copy: TOptions; begin Original := TOptions.Create; {this is what you use elsewhere} ... Copy := TOptions.Create; {create a copy} Copy.MakeCopy(Original); OptionsForm.Options := Copy; {the form works with the copy} if OptionsForm.ShowModal = mrOK then Original.MakeCopy(Copy); {change the original if OK} Copy.Free; {destroy the copy} ... end; Having all the options gathered together in a class is very helpful in lots of other places. And the same approach, using a MakeCopy method, works when editing any kind of object. You can also define MakeCopy as a function that returns an object of TOptions. The function would create the copy, but you'll have to remember to free it later. ********************************************************** procedure TPrintForm1.FormCreate(Sender: TObject); begin Screen.Cursor := crHourGlass; Application.CreateForm(TPrintForm2, PrintForm2); more..... Screen.Cursor := crDefault; end; ********************************************************** Kerry, You should be able to do something like this in your Project Source file where Unit1, Form1 is your 'run application [Ok] [Cancel]' interface and Unit2, Form2 is your application main form: program Project1; uses Forms, Controls {mrOk}, Unit1 in 'Unit1.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2}; {$R *.RES} var Result: Integer; Form1: TForm; begin Form1 := TForm1.Create(nil); Result := Form1.ShowModal; Form1.Free; Form1 := nil; if Result = mrOk then begin Application.Initialize; Application.CreateForm(TForm2, Form2); Application.Run; end; end. In other words, Form1 is created as an interface before you create the main application forms. If the user doesn't want to enter the system (Result = mrCancel or <> mrOk), then the application never starts. I assume this will work in D1; it works fine in D3. Steve Helgeson Lamplighter Software -----Original Message----- From: Sanders, Kerry [mailto:Kerry.Sanders@arbitron.com] Sent: 21 April 1999 22:06 To: 'Delphi List' Subject: Preventing Flicker I am currently working on an application written in Delphi v1.02 [yes.. some of us are still cursed! :-)]. When our application launches, it display a splash/progress screen while it is initializing some data. When this disappears, and before our main form shows, a user listbox dialog display. The user can select their name and click OK, or they can click Cancel if they decide not to use the system. The problem comes in when they choose to Cancel. All of the initialization and subsequent user selection occurs in the FormCreate procedure of the main form. Even though we issue an Application.Terminate, the main form pops up and then disappears when the user selects to Cancel. It is so fast, it is like a flicker. Does anyone know of what I might do to prevent this in a 16 bit application? I know about the Application.ShowMainForm variable in Delphi 4, but unfortunately, something that easy is not available in the 16 bit version of Delphi.