RAD Studio
ContentsIndex
PreviousUpNext
Making a dialog box a component
Name 
Description 
Before proceeding, decide on the properties your wrapper needs to enable developers to use your dialog box as a component in their applications. Then, you can add declarations for those properties to the component's class declaration.
Properties in wrapper components are somewhat simpler than the properties you would create if you were writing a regular component. Remember that in this case, you are just creating some persistent data that the wrapper can pass back and forth to the dialog box. By putting that data in the form of properties, you enable developers to set data at design time so that... more 
The final part of the component interface is a way to open the dialog box and return a result when it closes. As with the common dialog box components, you use a boolean function called Execute that returns True if the user clicks OK, or False if the user cancels the dialog box.
The declaration for the Execute method always looks like this:  
Creation of every component begins the same way: create a unit, derive a component class, register it, compile it, and install it on the Tool palette. This process is outlined in Creating a new component.
For this example, follow the general procedure for creating a component, with these specifics:
  • Call the component's unit AboutDlg.
  • Derive a new component type called TAboutBoxDlg, descended from TComponent.
  • Register TAboutBoxDlg on the Samples page of the Tool palette.
The resulting unit should look like this:  
These are the steps to create the component interface:
  1. Including the form unit files.
  2. Adding interface properties.
  3. Adding the Execute method.
 
Before you can create the component for your dialog box, you need to decide how you want developers to use it. You create an interface between your dialog box and applications that use it.
For example, look at the properties for the common dialog box components. They enable the developer to set the initial state of the dialog box, such as the caption and initial control settings, then read back any needed information after the dialog box closes. There is no direct interaction with the individual controls in the dialog box, just with the properties in the wrapper component.
The... more 
For your wrapper component to initialize and display the wrapped dialog box, you must add the form's unit to the uses clause of the wrapper component's unit.
Append About to the uses clause of the AboutDlg unit.
The uses clause now looks like this:  
You will find it convenient to make a frequently used dialog box into a component that you add to the Tool palette. Your dialog box components will work just like the components that represent the standard common dialog boxes. The goal is to create a simple component that a user can add to a project and set properties for at design time.
Making a dialog box a component requires these steps:
  1. Defining the component interface
  2. Creating and registering the component
  3. Creating the component interface
  4. Testing the component
The Delphi "wrapper" component associated with the dialog box creates and executes the... more 
Once you have installed the dialog box component, you can use it as you would any of the common dialog boxes, by placing one on a form and executing it. A quick way to test the About box is to add a command button to a form and execute the dialog box when the user clicks the button. 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!