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

Langage Delphi Discussion :

Combobox intégré a un composant, propriété


Sujet :

Langage Delphi

  1. #1
    Futur Membre du Club
    Homme Profil pro
    stagiaire développement informatique
    Inscrit en
    Juillet 2014
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : stagiaire développement informatique

    Informations forums :
    Inscription : Juillet 2014
    Messages : 20
    Points : 9
    Points
    9
    Par défaut Combobox intégré a un composant, propriété
    Bonjour,

    J'ai un problème je voudrais remplir ma comboBox qui est intégrée sur un Panel de la même façon que l'on peut la remplir quand elle est libre. C'est a dire en allant dans la propriété 'items' et y rentrer un texte.

    J'ai réalisé le composant suivant :

    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
     
    ComboBox1: TComboBox;
    ComboBoxItem : Tstrings;
    (...)
    procedure ComboBoxAddItem  (item : Tstrings);
    (...)
    property ComboBItem : Tstrings read ComboBoxItem write ComboBoxAddItem;
    (...)
    procedure TMonPanel94.ComboBoxAddItem  (item : Tstrings);
    begin
      if ComboBoxItem<>item then
      begin
        ComboBoxItem:=item;
        ComboBox1.Items:=ComboBoxItem;
      end;
    end;
    (...)
    //dans le constructor
    ComboBox1:=TComboBox.create(self);
    ComboBox1.parent:=self;
    ComboBox1.setbounds(4,27,117,21);
    Maintenant j'ouvre une application j'y met mon composant et quand je clique sur le bouton pour remplir ma propriété ComboBItem je reçois le message suivant

    "Impossible d'affecter nil à TRichEditStrings"

    Voila je rajoute mon code en entier au cas ou il manquerait une information. Merci de votre aide

    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
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    unit MyPanel94;
    interface
    uses
      SysUtils, Classes,Windows, Controls, Graphics,Messages,
      ExtCtrls,StdCtrls,QGraphics,JvComponent, JvTransLED,ImgList,Dialogs,JvEdit;
    type
      TMonPanel94 = class(TCustomPanel)
      private
         {Déclarations privées}
     
         Num : integer;
     
         //mon edit
         Label1: Tlabel;
         //titre
         LabelTitre: string;
         //EditTextLargeur:boolean;
         LabelCouleur : Tcolor;
         SharpCouleur : Tcolor;
     
     
         Edit1:Tedit;
         ComboEdit : boolean;
         EditMsg : string;
     
         //ma combobox
         ComboBox1: TComboBox;
       //  ComboBoxItem : Tstrings;
         ComboBoxItem : Tstrings;
     
         //fond gris
         Shape1: TShape;
     
         //ma led
         LED1: TJvTransLED;
         //led visible ou non
         LEDBoolVisible:boolean;
         //indice pour changer la couleur de la led
         LedCoul: integer;
     
         //Ma liste d'image
         ImgList: TImageList;
         //Mon emplacement d'image
         Img: TImage;
         ImgDessin:integer;///test
         ImgNb : integer;
         ImgExist : boolean;
         ImgListNom : string;
     
     
      protected
        { Déclarations protégées }
        procedure RedimLabel();
     
      public
        { Déclarations publiques }
     
        //On construit le composant
         constructor Create(AOwner: TComponent); override;
         //on détruit le composant
         Destructor  Destroy; override;
         //défini la couleur de la led
     
         //changement d'indice pour l'image
         procedure ImgOnChange(valIndex:integer);
         //permet de récupérer une liste d'image
         procedure ImgSetList(ImgNewList: TImageList);
     
         //On met le titre de notre composant en changeant le caption du label
         procedure LabelSetTitre(value : string);
     
         //On défini si la led doit être visible ou non
         procedure LedSetVisible (LEDvisu : Boolean);
         //défini la couleur de la led
         procedure LedSetCouleur (Coul : integer);
     
         //couleur du label
         Procedure LabelsetCouleur (LColor:Tcolor);
     
         Procedure SharpsetCouleur (SColor:Tcolor);
     
         //ajouter un item dans la combobox
         procedure ComboBoxAddItem  (item : Tstrings);
     
         //choisir entre combobox ou edit
         Procedure ChoixComboEdit (choix : boolean);
     
         //remplir le text de l'edit
         Procedure EditSetMessage (mess : string);
     
         //fixer un numero a notre composant
         procedure setNum (nb : integer);
     
         property Titre2FondCouleur : Tcolor read SharpCouleur write SharpsetCouleur;
     
     
      published
     ////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////
        property Align           ; //
        property Alignment       ; //
        property Anchors         ; //
        property Autosize        ; //
        property BevelWidth      ; //
        property BiDiMode        ; //
        property BorderStyle     ; //
        property BorderWidth     ; //
        property Caption         ; //
        property Color           ; //
        property Constraints     ; //
        property Ctl3D           ; //
        property Cursor          ; //
        property DockSite        ; //
        property DragCursor      ; //
        property DragKind        ; //
        property DragMode        ; //     Propriétés d'un panel classique
        property Enabled         ; //
        property Font            ; //
        property FullRepaint     ; //
        property Height          ; //
        property HelpContext     ; //
        property HelpType        ; //
        property Left            ; //
        property Locked          ; //
        property Name            ; //
        property ParentBackground; //
        property ParentColor     ; //
        property ParentCtl3D     ; //
        property ParentFont      ; //
        property ParentShowHint  ; //
        property Showhint        ; //
        property TabOrder        ; //
        property Visible         ; //
     /////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////
     
        //change l'édit
        property Titre : string read LabelTitre write LabelSetTitre;
     
        //change la couleur de la led (-1 gris, 0rouge et 1bleu)
        property LedCouLeur : integer read LedCoul write LedSetCouleur;
        //led visible ou non
        property LedVisible : boolean read LEDBoolVisible write LedSetVisible;
     
        //crée la liste d'images
        property Images: TImageList read ImgList write ImgSetList;
     
        //on dessine
        property ImgIndex : integer read ImgDessin  write ImgOnChange;
        //couleur sharp
        Property TitreFondCouleur :Tcolor read LabelCouleur write LabelsetCouleur ;
     
        //combobox
        property ComboBItem : Tstrings read ComboBoxItem write ComboBoxAddItem;
     
        //On met une combobox ou un edit
        Property ComboOuEdit : boolean read ComboEdit write ChoixComboEdit;
     
        //message dans l'edit
        property EditMessage : string read EditMsg write EditSetMessage;
     
        //fixer un numero sur notre composant
        property numero : integer read Num write setNum;
     
      end;
     
    procedure Register;
     
    implementation
     
    //fixe un numero
    procedure TMonPanel94.setNum(nb:integer);
    begin
      if Num<>nb then num:=nb;
    end;
     
    //On change le message dans l'eddit
    procedure TMonPanel94.EditSetMessage(mess : string);
    begin
      if (EditMsg<>mess) then
      begin
        EditMsg:=mess;
        Edit1.Text:=EditMsg;
      end;
    end;
     
    //ON affiche soit une combobox soit un edit
    Procedure TMonPanel94.ChoixComboEdit(choix:boolean);
    begin
      if ComboEdit <> choix then
      begin
        ComboEdit:=choix;
        if comboEdit=true then
        begin
          comboBox1.Visible:=true;
          Edit1.Visible:=false;
        end;
        if ComboEdit=false then
        begin
          ComboBox1.Visible:=false;
          Edit1.visible:=true;
        end;
      end;
    end;
     
    //on ajoute un item dans la combobox
    procedure TMonPanel94.ComboBoxAddItem  (item : Tstrings);
    begin
      if ComboBoxItem<>item then
      begin
        ComboBoxItem:=item;
        ComboBox1.Items:=ComboBoxItem;
      end;
    end;
     
    procedure TMonPanel94.SharpsetCouleur(Scolor:tcolor);
    begin
      if LabelCouleur<>Scolor then
      begin
      LabelCouleur:=Scolor;
      Shape1.Brush.Color:=LabelCouleur;
      Shape1.Pen.Color:=LabelCouleur;
      end;
    end;
     
    Procedure TMonPanel94.LabelsetCouleur (LColor:Tcolor);
    begin
      if LabelCouleur <> Lcolor then
      begin
        LabelCouleur:=Lcolor;
        Label1.color := LabelCouleur;
        Shape1.Brush.Color:=LabelCouleur;
        Shape1.Pen.Color:=LabelCouleur;
      end;
    end;
     
     
    //On prend en compte la nouvelle liste d'images
    procedure TMonPanel94.ImgSetList(ImgNewList: TImageList);
    begin
      if ImgList <> ImgNewList then
      begin
        ImgList:=ImgNewList;
       // ImgListNom := ImgNewList.Name;
       // ImgList.name:=ImgListNom;
      end;
    end;
     
     
    //On dessine l'image comprise dans la l'image liste, à l'intérieur du cadre délimité par l'image
    procedure TMonPanel94.ImgOnChange (ValIndex:integer);
    begin
      if ValIndex<>ImgDessin then
      begin
        ImgExist:=false;
        ImgDessin:=ValIndex;
        ImgNb:=ImgList.count;
         Img.Picture.Bitmap := nil;
        if ImgNB>ImgDessin then
        begin
          if ValIndex>-1 then
          begin
            ImgList.GetBitmap(valIndex, Img.Picture.Bitmap);
            ImgExist:=true;
          end;
        end;
      end;
      RedimLabel;
    end;
     
     
    //On prend en compte un changement visible ou non
    procedure TMonPanel94.LedSetVisible (LEDvisu : boolean);
    begin
      if (LEDvisu<>LEDBoolVisible) then
      begin
        LEDBoolVisible:=LEDvisu;
        LED1.Visible:=LEDBoolVisible;
      end;
      RedimLabel();
    end;
     
    procedure TMonPanel94.RedimLabel();
    begin
      label1.Width:=80;
      Label1.Left:=22;
      if ImgExist=true then
      begin
        label1.Left:=Label1.left+24;
        Label1.Width:=Label1.width-24 ;
      end;
      if LED1.Visible=true then
      begin
        Label1.Width:=label1.width-20;
      end;
    end;
     
     
    //On défini la couleur de la diode
    procedure TMonPanel94.LedSetCouleur (Coul : integer);
    begin
      LedCoul := coul;
      if Ledcoul<2 then
      begin
        if ledcoul>-2 then
        begin
         case coul of
         -1 : LED1.color:= clSilver;
          0 : LED1.color:= clRed;
          1 : LED1.color := clLime;
          end;
        end;
       end;
    end;
     
    procedure Register;
    begin
      RegisterComponents('Standard', [TMonPanel94]);
    end;
     
    //on défini le teste du edit  et donc le titre de notre composant
    procedure TMonPanel94.LabelSetTitre(value : string);
    begin
      if (LabelTitre <> value) then
      begin
        LabelTitre:=value;
        Label1.Caption:=LabelTitre;
        Label1.Alignment:=taCenter;
      end;
    end;
     
     
    constructor TMonPanel94.Create(Aowner:Tcomponent);
    begin
      //on crée le panel
      inherited create(Aowner);
      Width  := 125;
      Height := 50;
     
      //Images := ImgList;
     
     
      //on initialise et on place la combobox
      ComboBox1:=TComboBox.create(self);
      ComboBox1.parent:=self;
      ComboBox1.setbounds(4,27,117,21);
      //Combobox1.items:=clear;
     // Combobox1.clear;
     
      Edit1:=TEdit.create(self);
      Edit1.Parent:=self;
      Edit1.SetBounds(4,27,117,21);
      Edit1.ReadOnly:=true;
     
      //On initialise l'imageliste
       Imglist:=TImageList.create(self);
       //ImgList.name:=ImgListNom;
     // Imglist.Name := 'MonImageList';
       ImgDessin := -1;
     
     
      //fond gris
      Shape1:=TShape.create(self);
      Shape1.parent:=self;
      Shape1.setBounds(0,0,125,24);
      Titre2FondCouleur:=$BABABA;
     
        //On initialise et on place le label
      Label1:=TLabel.create(self);
      Label1.parent:=Self;
      Label1.setbounds(22,4,80,16);
      Label1.AutoSize:=false;
      Label1.alignment:=taCenter;
      Label1.Caption:='titre';
      Label1.Color:=$BABABA;
      Label1.font.Size:=9;
      Label1.Font.Style:=[Graphics.fsBold];
      //Label1.color:=Shape1.Brush.Color;
     
      //On itnitialise et on place le cadre de l'image
      Img:=TImage.create(self);
      Img.parent:=self;
      Img.setbounds(4,4,16,16);
      Img.Visible:=true;
     
     
      //On initialise la Led
      LED1:=TJvTransLED.create(self);
      LED1.parent :=self;
      LED1.setbounds (110,7,10,10);
      LED1.visible:=false; // sinon elle est tjr allumée
      Shape1.Pen.Color:=$BABABA;
     
     
      //On ne veut pas que le panel ait de caption
      Caption:=' ';
    end;
     
       //on détruit
      destructor TMonPanel94.Destroy;
        begin
          inherited destroy;
        end;
    end.

  2. #2
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 385
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 385
    Points : 2 999
    Points
    2 999
    Par défaut
    J'intégrerai plutôt la combo de la façon suivante:

    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
     
    unit MyPanel94;
     
    interface
     
    uses
      SysUtils, Classes, Windows, Controls, Graphics, Messages,
      ExtCtrls, StdCtrls, ImgList, Dialogs;
     
      type
     
      TMonPanel94 = class(TPanel)
      private
        FMaComboBox: TComboBox;
      public
        constructor Create(AOwner: TComponent); override;
      published
        property MaComboBox: TComboBox read FMaComboBox write FMaComboBox;
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
      RegisterComponents('MaPalette', [TMonPanel94]);
    end;
     
    constructor TMonPanel94.Create(Aowner:Tcomponent);
    begin
     
      inherited create(Aowner);
      Width  := 125;
      Height := 150;
     
      //on initialise et on place la combobox
      FMaComboBox := TComboBox.create(self);
      FMaComboBox.parent := self;
      FMaComboBox.setbounds(4, 50, 117, 21);
      FMaComboBox.Visible := True;
      FMaComboBox.SetSubComponent(True);
     
    end;
     
    end.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    stagiaire développement informatique
    Inscrit en
    Juillet 2014
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : stagiaire développement informatique

    Informations forums :
    Inscription : Juillet 2014
    Messages : 20
    Points : 9
    Points
    9
    Par défaut
    Ca fonctionne !! merci beaucoup a toi

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 06/01/2013, 13h49
  2. VB6, Combobox ne possède pas la propriété Sorted
    Par Samyy17 dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 18/11/2011, 11h38
  3. [DXE] Composant : Propriété non trouvée en exécution
    Par Rayek dans le forum Composants VCL
    Réponses: 1
    Dernier message: 21/04/2011, 15h50
  4. composant propriété inspecteur d'objet
    Par dédé dans le forum C++Builder
    Réponses: 3
    Dernier message: 23/09/2010, 18h17
  5. Alignement de composants (Propriétés Align)
    Par gibet_b dans le forum Delphi
    Réponses: 9
    Dernier message: 13/06/2006, 15h13

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