Board index » delphi » Events for run-time created components

Events for run-time created components

An application I am working on needs to create some components at run-time.
The problem is how to inherit an existing component's event, or create
events for non existing components at design-time.

Here is my approach:

....
type
 { an array of RichEdit components }
 TRich = array [1..100] of TRichEdit;
....
var
  Rich: TRich;
  { a counter used to create new RichEdit components }
  { and 'i' is used to refer array element }
  Count, i: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
{ set counter to zero }
Count := 0;
end;

procedure TForm1.cmdNewRichClick(Sender: TObject);
begin
{ increase the count }
Count := Count + 1;
{ create a new RichEdit component in array }
Rich[Count] := TRichEdit.Create(self);
  with Rich[Count] do
  begin
  Parent := Form1;
  Text := 'RichEdit';
  end;
end;

end.

As far as creating and handling run-time components this seems to work
fine, but Rich[i] has no events, such as OnChange, or OnKeyDown. Is it
possible for these new RichEdit components, in the array, to respond to
events, or inherit events from an existing RichEdit component? If so How?

Anthony M Walter
email: antho...@metrolink.net

 

Re:Events for run-time created components


"Anthony M Walter" <antho...@metrolink.net> wrote:

Quote
>An application I am working on needs to create some components at run-time.
>The problem is how to inherit an existing component's event, or create
>events for non existing components at design-time.

>Here is my approach:

>....
>type
> { an array of RichEdit components }
> TRich = array [1..100] of TRichEdit;
>....
>var
>  Rich: TRich;
> ....

>As far as creating and handling run-time components this seems to work
>fine, but Rich[i] has no events, such as OnChange, or OnKeyDown. Is it
>possible for these new RichEdit components, in the array, to respond to
>events, or inherit events from an existing RichEdit component? If so How?

   Must be tested:

      TRichEdit(Rich[i]).OnClick := MyExistantRich.OnClick;

Quote
>Anthony M Walter
>email: antho...@metrolink.net

--

           ___                                              ___
           L_|_                                            _|_J
          ( -O>                                            <O- )
       ___//\J  __________________________________________  L/\\___
      //-,\    |                                          |    /,-\\
     || / \\   L   AVONTURE Christophe (c) AVC Software   J___// \ ||
   _ ''/\/ '---J    Christophe.Avont...@is.belgacom.be    L---' \/\'' _
  / \ //\\.    |__________________________________________|    .//\\ / \
 |_/\'/  ||                                                    ||  \'/\_|
      '   ||_  Uses WinProcs, WinTypes, Standard_Disclaimers; _||   '
          |__)                                               (__|

                 mailto:Christophe.Avont...@is.belgacom.be
     Check the following site (French): http://www.mygale.org/07/jmy51/

Other Threads