Mega Code Archive

 
Categories / Delphi / Forms
 

Converting a standard Delphi Form to an ActiveForm !

Title: Converting a standard Delphi Form to an ActiveForm ! Question: An easy approach... Answer: The technique that I prefer is easy to learn and the most flexible. In this technique, you make your existing Delphi form a child window of an otherwise ActiveForm. Because its a child form, youll have to add code to set some of its properties to reflect that factto remove the window frame, to align it to its parents client area, etc. This approach has several advantages. The first advantage is that its easy to get up and runningthe only thing you need to do thats not already done for you is to add code to create and embed your form in the ActiveForm. Another advantage is that unlike copying your code to the ActiveForms implementation file, this approach doesnt change your forms implementation at all. The code youre familiar with is still familiar. It also means the forms implementation unit can still be included in a regular Delphi application if you so desire. Steps to convert a Delphi form to an ActiveForm: Create a blank ActiveForm. In the forms property inspector, add an Create handler like the one shown below: Procedure TActiveForm1.FormCreate(Sender: TObject); begin // This code creates a child form that is just a normal // Delphi TForm. // This allows the form to be shown both as a normal // VCL form and as an ActiveForm. ChildForm := TForm1.Create( Self ); ChildForm.Parent := Self; ChildForm.Align := alClient; ChildForm.BorderStyle := bsNone; ChildForm.Visible := True; end; In the uses clause, add a reference to your forms unit (in this case, Unit1). Add the forms implementation unit to the project (in this case, Unit1.pas). Add the declaration of ChildForm to your TActiveForm1 class, like this: type TActiveForm1 = class ... .... public ChildForm: TForm1; .... end; Compile and test your form.