Board index » delphi » Events

Events

Hi everyone.

It's propably a stupid question, but I've never done this before:

I'm writting a new component and have some questions:

  How do you assign a event to a component from the source code (i'm
creating components at runtime)?
  My component look like this: i have a panel(1) that contains another
panel(2). how do I make an event OnFocus for the panel 2?

declarations:
type
  TFocusType = (fcOn,fcOff,fcMouseOut,fcClicked);
  TNormalType = record Left,Top : integer; end;
  TOnResizeEvent = procedure(Sender : TObject) of object;
  TBitmapPanel = class(TPaintBox)
  private
    FBitmap : TBitmap;
    procedure SetBitmap(bmp : TBitmap);
    function GetBitmap:TBitmap;
  public
    property Bitmap : TBitmap
     read GetBitmap write SetBitmap;
    procedure Paint; override;
    constructor Create(aOwner : TComponent); override;
    destructor Destroy; override;
  end;
  TThumbnailPanel = class(TCustomPanel)
  private
    FInit : boolean;
    FBitmapPanel : TBitmapPanel;
    FMouseDown : boolean;
    FLabel : TLabel;
    FFocus : TFocusType;
    FLabelNormal : TNormalType;
    FBitmapNormal : TNormalType;
    FSavedColor : TColor;
    FFocusColor : TColor;
    FOnGotFocus : TNotifyEvent;
    FOnLostFocus : TNotifyEvent;
    procedure SetPanelFocus(a : TFocusType);
    procedure SetTitle(a : string);
    function GetTitle:string;
    procedure CMMouseEnter(var msg: TMessage); message CM_MouseEnter;
    procedure CMMouseLeave(var msg: TMessage); message CM_MouseLeave;
    procedure SetBitmap(a:TBitmap);
    function GetBitmap:TBitmap;
    procedure SetLabelSize(a:integer);
    function GetLabelSize:integer;
  public
    procedure GotFocus; dynamic;
    procedure LostFocus; dynamic;
    procedure Init;
    procedure OnMyResize(var msg: TWMSize); message WM_Size;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
       X,Y: integer); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
       X,Y: integer); override;
    procedure ControlMouseUp(Sender: TObject; Button: TMouseButton;
       ShiftState: TShiftState; X,Y: integer);
    procedure ControlMouseDown(Sender: TObject; Button: TMouseButton;
       ShiftState: TShiftState; X,Y: integer);
    procedure ControlClick(Sender: TObject);
    property LabelSize : integer
     read GetLabelSize write SetLabelSize;
    property Focus : TFocusType
     read FFocus write SetPanelFocus;
    property Title : string
     read GetTitle write SetTitle;
    property FocusColor : TColor
     read FFocusColor write FFocusColor;
    constructor Create(aOwner : TComponent); override;
    destructor Destroy; override;
  published
    property OnGotFocus : TNotifyEvent
     read FOnGotFocus write FOnGotFocus;
    property OnLostFocus : TNotifyEvent
     read FOnLostFocus write FOnLostFocus;
    property Bitmap : TBitmap
     read GetBitmap write SetBitmap;
  end;
  TThumbnail = class(TCustomPanel)
  private
    FThumbnail : TThumbnailPanel;
    function GetFocusColor:TColor;
    procedure SetFocusColor(a:TColor);
    procedure SetBitmap(a:TBitmap);
    function GetBitmap:TBitmap;
    procedure SetLabelSize(a:integer);
    function GetLabelSize:integer;
  protected
    procedure OnMyResize(var msg: TWMSize); message WM_Size;
    function GetTitle:string;
    procedure SetTitle(a:string);
  public
    constructor Create(aOwner : TComponent); override;
    destructor Destroy; override;
  published
    property Caption : string
     read GetTitle write SetTitle;
    property FocusColor : TColor
     read GetFocusColor write SetFocusColor;
    property Bitmap : TBitmap
     read GetBitmap write SetBitmap;
    property LabelSize : integer
     read GetLabelSize write SetLabelSize;
    property BevelOuter;
    property BevelInner;
    property BevelWidth;
    property Color;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property FullRepaint;
    property Locked;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopUpMenu;
    property Visible;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnStartDrag;
  end;

---

                               ///|\\\
                              /( _ _ )\
                             /(  0 0  )\
    +-----------------------oOOo-(_)-oOOo------------------------+
    | Bojan Cekrlic    ...Always look on the bright side of life |
    +------------------------------------------------------------+
    |    ICQ: 8028223, pager: 8028...@pager.mirabilis.com        |
    |  che...@bigfoot.com                      b...@bigfoot.com  |
    |       --->    http://www.bigfoot.com/~checko/    <---      |
    +------------------------oooO--------------------------------+
                            (   )   Oooo
                             \ (    (   )
                              \_)    ) /
                                    (_/

 

Re:Events


On Wed, 15 Jul 1998 13:26:03 +0200, "Bojan Cekrlic"

Quote
<che...@bigfoot.com> wrote:
>Hi everyone.

>It's propably a stupid question, but I've never done this before:

>I'm writting a new component and have some questions:

>  How do you assign a event to a component from the source code (i'm
>creating components at runtime)?
>  My component look like this: i have a panel(1) that contains another
>panel(2). how do I make an event OnFocus for the panel 2?

Try something like

private
  procedure MyOnEnter (Sender: TObject);

OnCreate:
  Panel2.OnEnter:= MyOnEnter;

It doesn't matter that the Panel2 is placed on Panel1.

Please check your sig. It is not delimited correctly by '-- ' and it
is a little bit tooooo long.

F'Up: comp.lang.pascal.delphi.misc

Udo Burghardt

Re:Events


Quote

>>Hi everyone.

>>It's propably a stupid question, but I've never done this before:

>>I'm writting a new component and have some questions:

>>  How do you assign a event to a component from the source code (i'm
>>creating components at runtime)?
>>  My component look like this: i have a panel(1) that contains another
>>panel(2). how do I make an event OnFocus for the panel 2?

>Try something like

>private
>  procedure MyOnEnter (Sender: TObject);

>OnCreate:
>  Panel2.OnEnter:= MyOnEnter;

>It doesn't matter that the Panel2 is placed on Panel1.

1. If I do that I get an error: Error: F:\FindPic!\Unit1.pas (238):
Incompatible types: 'TNotifyEvent' and 'Procedure.
2. You misunderstood me (which is my fault). I wanted to say, that I have
two panels (1) and (2), (1) is placed inside (2) and I want to generate
OnFocus event for panel (2) when the mouse enters panel (1)...

Bojan

If replying by e-mail change no-spam-please to bigfoot.com.

Other Threads