Board index » delphi » events for runtime created components

events for runtime created components

I have created a TPanel component at runtime.  I see the panel on my form.
I have given it a name and it is enabled.
I am trying to get it to respond to a mousedown event.  I declared a
mousedown procedure for the panel and
put a showmessage in the procedure but nothing is happening. In fact I
can't get any events to occur.  What do I need to do to access an event for
a run-time created component.

john kerns

 

Re:events for runtime created components


On 14 Jan 1998 00:59:29 GMT, "John Kerns" <slambe...@mindspring.com>
wrote:

Quote
> What do I need to do to access an event for a run-time created component.

Here's a concrete example which demonstrates what you are trying to
accomplish. See the comments for details.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  public
    Panel1 : TPanel;
    procedure MouseDownHandler(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  { Create panel at run-time }
  Panel1 := TPanel.Create(Self);
  { Assign some values to the panel's properties }
  Panel1.SetBounds(0, 0, 120, 40);
  Panel1.Caption := 'Please do not click!';
  { Controls aren't visible until their Parent property is set }
  Panel1.Parent := Self;
  { Assign an event-handler method to a panel event }
  Panel1.OnMouseDown := MouseDownHandler;
end;

{ MouseDownHandler is type-compatible with TPanel OnMouseDown,
   which is declared as TMouseEvent. Type-compatible means it has
   the same parameters. }
procedure TForm1.MouseDownHandler(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ShowMessage('Ouch. Stop clicking me, you cretin.');
end;

end.

--
Rick Rogers (TeamB) | Fenestra Technologies

Re:events for runtime created components


Using RX Tools animated icon on the Tray. Need to replace an existing
animation file with another one (which means the current animation will
change).
Has anyone been down this track, and if so, can u point me to the resource
for info, or better still a code snippet?
Thanks vm.
Alistair George+

Re:events for runtime created components


Big Al:

Have you had any luck with solving this problem?
I too am looking for a way to replace the Icons(TIconList) at runtime,

preferably from a resource.

I'm anxious to know if anyone out there has done such a thing.

TIA,

Joe

On Wed, 14 Jan 1998 14:50:30 +1300, "Alistair George"

Quote
<bi...@xtra.co.nz> wrote:
>Using RX Tools animated icon on the Tray. Need to replace an existing
>animation file with another one (which means the current animation will
>change).
>Has anyone been down this track, and if so, can u point me to the resource
>for info, or better still a code snippet?
>Thanks vm.
>Alistair George+

Joe Apperson
Data Consultants, Inc.
www.routeman.com

Re:events for runtime created components


Quote
Joe Apperson wrote:

> Big Al:

> Have you had any luck with solving this problem?
> I too am looking for a way to replace the Icons(TIconList) at runtime,

> preferably from a resource.

> I'm anxious to know if anyone out there has done such a thing.

> TIA,

> Joe

> On Wed, 14 Jan 1998 14:50:30 +1300, "Alistair George"
> <bi...@xtra.co.nz> wrote:

> >Using RX Tools animated icon on the Tray. Need to replace an existing
> >animation file with another one (which means the current animation will
> >change).
> >Has anyone been down this track, and if so, can u point me to the resource
> >for info, or better still a code snippet?
> >Thanks vm.
> >Alistair George+

> Joe Apperson
> Data Consultants, Inc.
> www.routeman.com

This worked for me! Try this way:

procedure TForm1.ChangeList1Click(Sender: TObject);
var
  MyIcon : TIcon;
begin
  MyIcon := TIcon.Create;
  MyIcon.LoadFromFile('C:\D3\Images\Icons\arrow3a.ico');
  RxTrayIcon1.Icons[0] := MyIcon;
  MyIcon.LoadFromFile('C:\D3\Images\Icons\arrow3b.ico');
  RxTrayIcon1.Icons[1] := MyIcon;
  MyIcon.LoadFromFile('C:\D3\Images\Icons\arrow3c.ico');
  RxTrayIcon1.Icons[2] := MyIcon;
  MyIcon.LoadFromFile('C:\D3\Images\Icons\arrow3d.ico');
  RxTrayIcon1.Icons[3] := MyIcon;
  MyIcon.Free;
end;
--
Eddie Shipman
Marketing Systems Group
Austin, Texas
(512) 707-5157
eship...@inetport.com

Other Threads