Board index » delphi » Turning a form into a (non-visual) component?

Turning a form into a (non-visual) component?

I have created a form which browses datasets.
It's self-contained and I'd like to turn it
into a non-visual component, which I could call
like the CommonDialog forms, ie.

  DataSetBrowser.Show(pDataSet : TDataSet);

I've never written a component, so I would
appreciate any hints as to how I'd go about
turning the form into a component.

- Morten

 

Re:Turning a form into a (non-visual) component?


Quote
On Tue, 12 Jan 1999, Morten Br?ten wrote:
> I have created a form which browses datasets.
> It's self-contained and I'd like to turn it
> into a non-visual component, which I could call
> like the CommonDialog forms, ie.

>   DataSetBrowser.Show(pDataSet : TDataSet);

> I've never written a component, so I would
> appreciate any hints as to how I'd go about
> turning the form into a component.

> - Morten

Hi,
to make a non-visual component you must:
1 select Component->New component...
2 inherit by the class TComponent (to make non-visual component)
  this will make appear a new unit with a declaration of the obj you want
3 Add the methods you need (i.e. procedure Open(pDataSet: TDataSet) that
  is the method Show of your example (I don't think you can overload it,
  that is the why is better if you call it Open))
4 remember to override Create and Destroy methods:
        constructor Create(AOwner: TComponent)
        begin
                inherited Create;
                // allocation of the structure you need
        end;

        destroier Destroy;
        begin
                // destroy the structure you need
                inherited Destroy;
        end;

In your case, the component must have a TForm and the other components
you want to place on it, declared as members (private or public or
protected as you need them), then in the constructor you must set
properly all the properties of them.

I hope that this little Mail can help you (and that I didn't forget
somethikgs). I apologize for my poor english.  

Other Threads