IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

Problèmes evenements et propriété


Sujet :

Delphi

  1. #1
    Membre actif Avatar de Basile le disciple
    Homme Profil pro
    étudiant Centrale Supélec
    Inscrit en
    Avril 2013
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : étudiant Centrale Supélec

    Informations forums :
    Inscription : Avril 2013
    Messages : 147
    Points : 279
    Points
    279
    Par défaut Problèmes evenements et propriété
    J'ai essayé de faire un objet graphique et j'essaie de gérer des evenements. Sauf que ça ne marche pas(sauf le OnPaint).Pourquoi? et comment y remédier? De plus, ma propriété PopupMenu ne marche pas.

    code ci-joint :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
     
    unit UPaintbox32;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls, Menus, ComCtrls;
     
                   ///////////////////
                   //* TPaintbox32 *//
                   ///////////////////
     
    type
      TMouseEvent = procedure(sender : TObject;shift : TShiftState;x,y : integer) of object;
      TKeyPressEvent = procedure(Sender: TObject; var Key: Char) of object;
      TMouseWheelEvent =procedure(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean) of object;
      TPaintbox32 = class(TWINCONTROL)
      private
          //f
        fwidth,fheight,ftop,fleft,fTag : integer;
        fClientRect : TRect;
        fHelpKeyWord,fhint : string;
        fHelpType : THelpType;
        fDragKind : TDragKind;
        fDragCursor,fCursor : TCursor;
        fDragMode : TDragMode;
        fAlign : TAlign;
        fHelpContext : THelpContext;
        fPopupMenu : TPopupMenu;
        fClientOrigin : TPoint;
        fShowHint,fVisible : boolean;
        fAnchors : TAnchors;
        fConstraints : TSizeConstraints;
          //evenements
        fPaint,fClick,fdblclick : TNotifyEvent;
        fMouseMove : TMouseEvent;
        fKeyPress : TKeyPressEvent;
        fMouseWheel : TMouseWheelEvent;
          //objets
        Paintbox1 : TPaintbox;
        bmp : TBitmap;
        Button : TButton;
        SCrollBox : TScrollBox;
          //procedure
        procedure Paint(sender : TObject);
        procedure clic(sender : TObject);
        procedure dblclic(sender : TObject);
        procedure setleft(x : integer);
        procedure settop(x : integer);
        procedure setwidth(x : integer);
        procedure setheight(x : integer);
        procedure setCanvas(x : TCanvas);
        procedure setCursor(x : TCursor);
        procedure setAlign(x : TAlign);
        procedure setAnchors(x : TAnchors);
        procedure setConstraints(x : TSizeConstraints);
        procedure setDragCursor(x : TCursor);
        procedure setDragKind(x : TDragKind);
        procedure setDragMode(x : TDragMode);
        procedure setHelpContext(x : THelpContext);
        procedure setHelpKeyWord(x : string);
        procedure setHelpType(x : THelpType);
        procedure setPopupMenu(x : TPopupMenu);
        procedure setTag(x : integer);
        procedure setHint(x : string);
        procedure setShowHint(x : boolean);
        procedure setVisible(x : boolean);
        procedure move(Sender: TObject; Shift: TShiftState; X,Y: Integer);
        procedure KeyPress(Sender: TObject; var Key: Char);
        procedure MouseWheel(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
          // function
       function getCanvas : TCanvas;
      public
          //constructor
        constructor create (aowner : TWINCONTROL);
          //canvas
        property Canvas : TCanvas read getcanvas write setcanvas;
          //procedure
        procedure BringToFront;
        procedure SendToBack;
      published
          //property
        property Left : integer read fleft write setleft;
        property Top : integer read ftop write settop;
        property Width : integer read fwidth write setwidth;
        property Height : integer read fheight write setheight;
        property ClientRect : TRect read fClientRect;
        property Constraints : TSizeConstraints read fConstraints write setConstraints;
        property Cursor : TCursor read fCursor write setCursor;
        property ClientOrigin : TPoint read fClientOrigin;
        property Align : TAlign read fAlign write setAlign;
        property Anchors : TAnchors read fAnchors write setAnchors;
        property DragCursor : TCursor read fDragCursor write setDragCursor;
        property DragKind : TDragKind read fDragKind write setDragKind;
        property DragMode : TDragMode read fDragMode write setDragMode;
        property HelpContext : THelpContext read fHelpContext write setHelpContext;
        property HelpKeyWord : string read fHelpKeyWord write setHelpKeyWord;
        property HelpType : THelpType read fHelpType write setHelpType;
        property PopupMenu : TPopupMenu read fPopupMenu write setPopupMenu;
        property Tag : integer read fTag write setTag;
        property Hint : string read fHint write setHint;
        property ShowHint : boolean read fShowHint write setShowHint;
        property Visible : boolean read fVisible write setVisible;
          //TNotifyEvent
        property OnPaint : TNotifyEvent read fPaint write fPaint;
        property OnClick : TNotifyEvent read fClick write fClick;
        property OndblClick : TNotifyEvent read fdblclick write fdblclick;
        property OnMouseMove : TMouseEvent read fMouseMove write fMouseMove;
        property OnKeyPress : TKeyPressEvent read fKeyPress write fKeyPress;
        property OnMouseWheel : TMouseWheelEvent read fMouseWheel write fMouseWheel;
      end;
     
     
    implementation
     
    constructor TPaintbox32.create(aowner : TWINCONTROL);
    begin
      inherited create(aowner);
      fWidth:=100;
      fHeight:=100;
      fVisible:=true;
        //create
      paintbox1:=TPaintbox.Create(aowner);
      ScrollBox:=TScrollBox.Create(aowner);
      Button:=TButton.Create(aowner);
      bmp:=TBitmap.Create;
        //with object do
      With Paintbox1 do
      begin
        parent:=aowner;
        Width:=fWidth;
        Top:=fTop;
        Left:=fLeft;
        Enabled:=false;
        Height:=fHeight;
        OnPaint:=Paint;
        OnClick:=clic;
        OndblClick:=dblClic;
        OnMouseMove:=move;
      end;
      With bmp do
      begin
        Width:=fWidth;
        Height:=fHeight;
      end;
      With Button do
      begin
        parent:=self;
        Visible:=true;
        BringToFront;
        Width:=fWidth;
        Height:=fHeight;
        OnKeyPress:=KeyPress;
      end;
      With ScrollBox do
      begin
        parent:=self;
        Width:=fWidth;
        Height:=fHeight;
        OnMouseWheel:=MouseWheel;
      end;
      fclientrect:=rect(0,0,fWidth,fHeight);
    end;
     
    procedure TPaintbox32.setleft(x : integer);
    begin
      fLeft:=x;
      Paintbox1.Left:=fLeft;
    end;
     
    procedure TPaintbox32.settop(x : integer);
    begin
      fTop:=x;
      Paintbox1.Top:=ftop;
    end;
     
    procedure TPaintbox32.setwidth(x : integer);
    begin
      fWidth:=x;
      Paintbox1.Width:=fWidth;
      bmp.Width:=fWidth;
      Button.Width:=fWidth;
      ScrollBox.Width:=fWidth;
      fClientRect:=rect(0,0,fwidth,fheight);
    end;
     
    procedure TPaintbox32.setheight(x : integer);
    begin
      fHeight:=x;
      Paintbox1.Height:=fHeight;
      bmp.Height:=fHeight;
      Button.Height:=fHeight;
      ScrollBox.Height:=fHeight;
      fClientRect:=rect(0,0,fwidth,fheight);
    end;
     
    procedure TPaintbox32.Paint(sender : TObject);
    begin
      if assigned(fPaint) then fPaint(self);
    end;
     
    procedure TPaintbox32.setCanvas(x : TCanvas);
    begin
      bmp.Assign(x);
    end;
     
    function TPaintbox32.getCanvas : TCanvas;
    begin
      result:=bmp.Canvas;
      if fVisible then Paintbox1.Canvas.Draw(0,0,bmp) else Paintbox1.Canvas.Draw(fWidth,fHeight,bmp);
    end;
     
    procedure TPaintbox32.setCursor(x : TCursor);
    begin
      Paintbox1.Cursor:=x;
      fCursor:=Paintbox1.Cursor;
    end;
     
    procedure TPaintbox32.move(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      fClientOrigin.X:=x;
      fClientOrigin.Y:=y;
      if assigned(fMouseMove) then fMouseMove(self,shift,x,y);
    end;
     
    procedure TPaintbox32.clic(sender : TObject);
    begin
      if assigned(fclick) then fclick(self);
    end;
     
    procedure TPaintbox32.dblclic(sender : TObject);
    begin
      if assigned(fdblclick) then fdblclick(self);
    end;
     
    procedure TPaintbox32.setAlign(x : TAlign);
    begin
      Paintbox1.Align:=x;
      fAlign:=Paintbox1.Align;
      fWidth:=Paintbox1.Width;
      fHeight:=Paintbox1.Height;
      With ScrollBox do
      begin
        Align:=fAlign;
      end;
        Button.Align:=fAlign;
        bmp.Width:=fWidth;
        bmp.Height:=fHeight;
        fclientrect:=rect(0,0,fWidth,fHeight);
    end;
     
    procedure TPaintbox32.setAnchors(x : TAnchors);
    begin
      Paintbox1.Anchors:=x;
      fAnchors:=Paintbox1.Anchors;
    end;
     
    procedure TPaintbox32.setConstraints(x : TSizeConstraints);
    begin
      Paintbox1.Constraints:=x;
      fConstraints:=Paintbox1.Constraints;
    end;
     
    procedure TPaintbox32.setDragCursor(x : TCursor);
    begin
      Paintbox1.DragCursor:=x;
      fDragCursor:=Paintbox1.DragCursor;
    end;
     
    procedure TPaintbox32.setDragKind(x : TDragKind);
    begin
      Paintbox1.DragKind:=x;
      fDragKind:=Paintbox1.DragKind;
    end;
     
    procedure TPaintbox32.setDragMode(x : TDragMode);
    begin
      Paintbox1.DragMode:=x;
      fDragMode:=Paintbox1.DragMode;
    end;
    procedure TPaintbox32.setHelpContext(x : THelpContext);
    begin
      Paintbox1.HelpContext:=x;
      fHelpContext:=Paintbox1.HelpContext;
    end;
     
    procedure TPaintbox32.setHelpKeyWord(x : string);
    begin
      Paintbox1.HelpKeyword:=x;
      fHelpKeyWord:=Paintbox1.HelpKeyword;
    end;
     
    procedure TPaintbox32.setHelpType(x : THelpType);
    begin
      Paintbox1.HelpType:=x;
      fHelpType:=Paintbox1.HelpType;
    end;
     
    procedure TPaintbox32.setPopupMenu(x : TPopupMenu);
    begin
      Paintbox1.PopupMenu:=x;
      fPopupMenu:=Paintbox1.PopupMenu;
    end;
     
    procedure TPaintbox32.setTag(x : integer);
    begin
      Paintbox1.Tag:=x;
      fTag:=Paintbox1.Tag;
    end;
     
    procedure TPaintbox32.BringToFront;
    begin
      Paintbox1.BringToFront;
    end;
     
    procedure TPaintbox32.SendToBack;
    begin
      Paintbox1.SendToBack;
    end;
     
    procedure TPaintbox32.setHint(x : string);
    begin
      Paintbox1.Hint:=x;
      fHint:=Paintbox1.Hint;
    end;
     
    procedure TPaintbox32.setShowHint(x : boolean);
    begin
      Paintbox1.ShowHint:=x;
      fShowHint:=Paintbox1.ShowHint;
    end;
     
    procedure TPaintbox32.setVisible(x : boolean);
    begin
      Paintbox1.Visible:=x;
      fVisible:=Paintbox1.Visible;
    end;
     
    procedure TPaintbox32.KeyPress(Sender: TObject; var Key: Char);
    begin
      key:=upCase(Key);
      if assigned(fKeyPress) then fKeyPress(self,key);
    end;
     
    procedure TPaintbox32.MouseWheel(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin
      if assigned(fMouseWheel) then fMouseWheel(self,shift,WheelDelta,MousePos,Handled);
    end;
     
     
    end.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls,UPaintbox32, StdCtrls, Menus, ComCtrls;
     
    type
      TForm1 = class(TForm)
        PaintBox1: TPaintBox;
        Timer1: TTimer;
        PopupMenu1: TPopupMenu;
        fgn1: TMenuItem;
        the1: TMenuItem;
        thyn1: TMenuItem;
        n1: TMenuItem;
        hyn1: TMenuItem;
        y1: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Déclarations privées }
        p : integer;
        Paintbox32 : TPaintbox32;
        procedure KeyPress2(sender : TObject;var Key : Char);
        procedure Paint2(sender : TObject);
        procedure dblclic(sender : TObject);
        procedure clic(sender : TObject);
        procedure Mouse(sender : TObject;shift : TShiftState;x,y : integer);
        procedure MouseWheel(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Paintbox32:=TPaintbox32.create(self);
      With Paintbox32 do
      begin
        Top:=100;
        Left:=100;
        Width:=200;
        Height:=200;
        Cursor:=crHandPoint;
        OnPaint:=Paint2;
        OnMouseMove:=Mouse;
        OnClick:=clic;
        OndblClick:=dblclic;
        OnKeyPress:=KeyPress2;
        OnMouseWheel:=mouseWheel;
        ShowHint:=true;
        Hint:='Hint';
      end;
    end;
     
    procedure TForm1.Paint2(sender : TObject);
    begin
      With Paintbox32.Canvas do
      begin
        Brush.Color:=clwhite;
        rectangle(Paintbox32.ClientRect);
        Brush.Color:=clred;
        Rectangle(p,90,p+20,110);
      end;
    end;
     
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      inc(p);
      Paint2(self);
    end;
     
    procedure TForm1.dblclic(sender : TObject);
    begin
      Caption:='OnDblClick';
    end;
     
    procedure TForm1.Mouse(sender : TObject;shift : TShiftState;x,y : integer);
    begin
      Caption:='OnMouseMove';
    end;
     
    procedure TForm1.clic(sender : TObject);
    begin
      Caption:='OnClick';
    end;
     
    procedure TForm1.KeyPress2(sender : TObject;var key : Char);
    begin
      Caption:='OnKeyPress';
    end;
     
    procedure TForm1.MouseWheel(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin
      Caption:='OnMouseWheel';
    end;
     
    end.
    Meci de répondre.

  2. #2
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 695
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 695
    Points : 13 133
    Points
    13 133
    Par défaut
    Parce que l'héritage n'est pas respecté. Pour que ton composant récupère les clicks, il faut redéfinir la méthode Click :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    protected
      procedure Click; override;
    Idem pour le reste.

  3. #3
    Membre actif Avatar de Basile le disciple
    Homme Profil pro
    étudiant Centrale Supélec
    Inscrit en
    Avril 2013
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : étudiant Centrale Supélec

    Informations forums :
    Inscription : Avril 2013
    Messages : 147
    Points : 279
    Points
    279
    Par défaut
    citation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    protected
      procedure Click; override;
    D'accord mais qu'est-ce que je mets dans la procedure click?
    Et comment je fais pour ma propriété PopupMenu?
    Sinon c'est sympa de m'avoir répondu aussi vite

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème excel ole : propriété leftheader
    Par cchatelain dans le forum Langage
    Réponses: 1
    Dernier message: 10/01/2006, 16h42
  2. [Delphi 6] Problème avec la propriété Text d'un composant
    Par bionoir dans le forum Composants VCL
    Réponses: 4
    Dernier message: 08/12/2005, 11h23
  3. [Problème] Accès aux propriétés de listes nommées avec []
    Par VincentL dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 05/10/2005, 16h13
  4. Réponses: 12
    Dernier message: 06/04/2005, 11h54
  5. Problème evenement clavier sous fire fox.
    Par fxp17 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 05/01/2005, 15h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo