Introduction
You could test the runtime behavior of a custom component before you install it on the Delphi IDE Component palette. This is useful for debugging existing and newly created custom components.
Implementation
Following are the steps required to test a newly created custom component, without installing it in the Deplhi Component palette:
1. Add the name of component's unit to the form unit's uses clause.
2. Add an object field to the form to represent the component.
3. Attach a handler to the form's OnCreate event.
4. Construct the component in the form's OnCreate handler.
5. Assign the Parent property of the component. A component's Parent could be set to Self, that is, the form.
6. Set any other component properties as required.
Thus, following is the code in your form unit, that would be used to test the custom component at runtime:
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, MyControl; { 1. Add NewTest to uses clause }
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject); { 3. Attach a handler to OnCreate }
private
{ Private declarations }
public
{ Public Declarations }
MyControl1: TMyControl1; { 2. Add an object field }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyControl1 := TMyControl.Create(Self); { 4. Construct the component }
MyControl1.Parent := Self; { 5. Set Parent property if component is a control }
MyControl1.Left := 12; { 6. Set other properties }
end;
end.