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 :

Propriété d'un objet qui marche pas


Sujet :

Delphi

  1. #1
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut Propriété d'un objet qui marche pas
    Bonjour

    Dans un objet j'ai déclaré un type (pos_verticale) que j'utilise dans une propriété (verticale).

    Quand je compile pas de problème ainsi que quand je change la propriété depuis l'explorateur d'objet mais quand je veux changer la propriété dans le programme ça va pas du tout.

    Voici un extrait du code de l'objet
    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
    interface
     
    uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls, 
         Forms, Graphics, Extctrls;
     
    { Unit-wide declarations }
    type
        Pos_verticale = (Haut,Bas,Milieu_haut,Milieu_bas,Centre,Haut_et_bas);
    { var }
         { . . . }
     
    type
      TChronologie = class(TPanel)
        private
          { Private fields of TChronologie }
            ...
            FVerticale : pos_verticale;
     
          { Private methods of TChronologie }
            { Method to set variable and property values and create objects }
            ...
            function GetVerticale : pos_verticale;
            procedure SetVerticale(Value : pos_verticale);
     
    ...
    function TChronologie.GetVerticale : pos_verticale;
    begin
         Result := FVerticale;
    end;
     
    procedure TChronologie.SetVerticale(Value : pos_verticale);
    begin
         FVerticale := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
    Dans le programme je change la propriété comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    chrono.verticale:=Haut;
    Voici l'erreur rencontrée
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [Erreur] Histoire_Unit1.pas(607): Types incompatibles : 'Pos_verticale' et 'Positionnement'
    Si vous avez une idée moi je sèche depuis un moment

    Merci d'avance


    Voici tout le code de l'objet
    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
    unit Chrono_chrono;
     
    interface
     
    uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls, 
         Forms, Graphics, Extctrls;
     
    { Unit-wide declarations }
    type
        Pos_verticale = (Haut,Bas,Milieu_haut,Milieu_bas,Centre,Haut_et_bas);
    { var }
         { . . . }
     
    type
      TChronologie = class(TPanel)
        private
          { Private fields of TChronologie }
            FAnnee_debut : Integer;
            FAnnee_fin : Integer;
            FCommentaire : TStrings;
            FDate_debut : String;
            FDate_fin : String;
            FLien_vers : String;
            FNumero_chronologie : Integer;
            FTitre : String;
            FVerticale : pos_verticale;
     
          { Private methods of TChronologie }
            { Method to set variable and property values and create objects }
            procedure AutoInitialize;
            { Method to free any objects created by AutoInitialize }
            procedure AutoDestroy;
            function GetAnnee_debut : Integer;
            procedure SetAnnee_debut(Value : Integer);
            function GetAnnee_fin : Integer;
            procedure SetAnnee_fin(Value : Integer);
            function GetCommentaire : TStrings;
            procedure SetCommentaire(Value : TStrings);
            function GetDate_debut : String;
            procedure SetDate_debut(Value : String);
            function GetDate_fin : String;
            procedure SetDate_fin(Value : String);
            function GetLien_vers : String;
            procedure SetLien_vers(Value : String);
            function GetNumero_chronologie : Integer;
            procedure SetNumero_chronologie(Value : Integer);
            function GetTitre : String;
            procedure SetTitre(Value : String);
            function GetVerticale : pos_verticale;
            procedure SetVerticale(Value : pos_verticale);
     
        protected
          { Protected fields of TChronologie }
     
          { Protected methods of TChronologie }
            procedure Click; override;
            procedure KeyPress(var Key : Char); override;
            procedure Loaded; override;
            procedure Paint; override;
     
        public
          { Public fields and properties of TChronologie }
            Echelle : real;
     
          { Public methods of TChronologie }
            constructor Create(AOwner: TComponent); override;
            destructor Destroy; override;
            procedure Place;
     
        published
          { Published properties of TChronologie }
            property OnClick;
            property OnDblClick;
            property OnDragDrop;
            property OnEnter;
            property OnExit;
            property OnKeyDown;
            property OnKeyPress;
            property OnKeyUp;
            property OnMouseDown;
            property OnMouseMove;
            property OnMouseUp;
            property OnResize;
            property Annee_debut : Integer
                 read GetAnnee_debut write SetAnnee_debut
                 default -2000;
            property Annee_fin : Integer
                 read GetAnnee_fin write SetAnnee_fin
                 default 2013;
            property Commentaire : TStrings
                 read GetCommentaire write SetCommentaire;
            property Date_debut : String read GetDate_debut write SetDate_debut;
            property Date_fin : String read GetDate_fin write SetDate_fin;
            property Lien_vers : String read GetLien_vers write SetLien_vers;
            property Numero_chronologie : Integer
                 read GetNumero_chronologie write SetNumero_chronologie
                 default 0;
            property Titre : String read GetTitre write SetTitre;
            property Verticale : pos_verticale
                 read GetVerticale write SetVerticale;
     
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
         { Register TChronologie with Chronologie as its
           default page on the Delphi component palette }
         RegisterComponents('Chronologie', [TChronologie]);
    end;
     
    { Method to set variable and property values and create objects }
    procedure TChronologie.AutoInitialize;
    begin
         FAnnee_debut := -2000;
         FAnnee_fin := 2013;
         FCommentaire := TStringList.Create;
         FDate_debut := 'XX/XX/1968';
         FDate_fin := '01/01/1968';
         FNumero_chronologie := 0;
    end; { of AutoInitialize }
     
    { Method to free any objects created by AutoInitialize }
    procedure TChronologie.AutoDestroy;
    begin
         FCommentaire.Free;
    end; { of AutoDestroy }
     
    function TChronologie.GetAnnee_debut : Integer;
    begin
         Result := FAnnee_debut;
    end;
     
    procedure TChronologie.SetAnnee_debut(Value : Integer);
    begin
         FAnnee_debut := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetAnnee_fin : Integer;
    begin
         Result := FAnnee_fin;
    end;
     
    procedure TChronologie.SetAnnee_fin(Value : Integer);
    begin
         FAnnee_fin := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetCommentaire : TStrings;
    begin
         Result := FCommentaire;
    end;
     
    procedure TChronologie.SetCommentaire(Value : TStrings);
    begin
         { Use Assign method because TStrings is an object type
           and FCommentaire has been created. }
         FCommentaire.Assign(Value);
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetDate_debut : String;
    begin
         Result := FDate_debut;
    end;
     
    procedure TChronologie.SetDate_debut(Value : String);
    begin
         FDate_debut := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetDate_fin : String;
    begin
         Result := FDate_fin;
    end;
     
    procedure TChronologie.SetDate_fin(Value : String);
    begin
         FDate_fin := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetLien_vers : String;
    begin
         Result := FLien_vers;
    end;
     
    procedure TChronologie.SetLien_vers(Value : String);
    begin
         FLien_vers := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetNumero_chronologie : Integer;
    begin
         Result := FNumero_chronologie;
    end;
     
    procedure TChronologie.SetNumero_chronologie(Value : Integer);
    begin
         FNumero_chronologie := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetTitre : String;
    begin
         Result := FTitre;
    end;
     
    procedure TChronologie.SetTitre(Value : String);
    begin
         FTitre := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    function TChronologie.GetVerticale : pos_verticale;
    begin
         Result := FVerticale;
    end;
     
    procedure TChronologie.SetVerticale(Value : pos_verticale);
    begin
         FVerticale := Value;
     
         { If changing this property affects the appearance of
           the component, call Invalidate here so the image will be
           updated. }
         { Invalidate; }
    end;
     
    { Override OnClick handler from TPanel }
    procedure TChronologie.Click;
    begin
         { Code to execute before activating click
           behavior of component's parent class }
     
         { Activate click behavior of parent }
         inherited Click;
     
         { Code to execute after click behavior
           of parent }
     
    end;
     
    { Override OnKeyPress handler from TPanel }
    procedure TChronologie.KeyPress(var Key : Char);
    const
         TabKey = Char(VK_TAB);
         EnterKey = Char(VK_RETURN);
    begin
         { Key contains the character produced by the keypress.
           It can be tested or assigned a new value before the
           call to the inherited KeyPress method.  Setting Key
           to #0 before call to the inherited KeyPress method
           terminates any further processing of the character. }
     
         { Activate KeyPress behavior of parent }
         inherited KeyPress(Key);
     
         { Code to execute after KeyPress behavior of parent }
     
    end;
     
    constructor TChronologie.Create(AOwner: TComponent);
    begin
         { Call the Create method of the container's parent class       }
         inherited Create(AOwner);
     
         { AutoInitialize sets the initial values of variables          }
         { (including subcomponent variables) and properties;           }
         { also, it creates objects for properties of standard          }
         { Delphi object types (e.g., TFont, TTimer, TPicture)          }
         { and for any variables marked as objects.                     }
         { AutoInitialize method is generated by Component Create.      }
         AutoInitialize;
     
         { Code to perform other tasks when the container is created    }
     
    end;
     
    destructor TChronologie.Destroy;
    begin
         { AutoDestroy, which is generated by Component Create, frees any   }
         { objects created by AutoInitialize.                               }
         AutoDestroy;
     
         { Here, free any other dynamic objects that the component methods  }
         { created but have not yet freed.  Also perform any other clean-up }
         { operations needed before the component is destroyed.             }
     
         { Last, free the component by calling the Destroy method of the    }
         { parent class.                                                    }
         inherited Destroy;
    end;
     
    procedure TChronologie.Loaded;
    begin
         inherited Loaded;
     
         { Perform any component setup that depends on the property
           values having been set }
     
    end;
     
    procedure TChronologie.Paint;
    begin
         { Make this component look like its parent component by calling
           its parent's Paint method. }
         inherited Paint;
     
         { To change the appearance of the component, use the methods
           supplied by the component's Canvas property (which is of
           type TCanvas).  For example, }
     
         { Canvas.Rectangle(0, 0, Width, Height); }
    end;
     
    procedure TChronologie.Place;
    var x1, x2 : integer;
    begin
      if (FAnnee_fin-FAnnee_debut)>0 then
            Echelle:=parent.width/(FAnnee_fin-FAnnee_debut)
                                        else
            Echelle:=0;
      x1:=trunc((strtoint(copy(fdate_debut,7,255))-FAnnee_debut)*Echelle);
      if x1<0 then x1:=0;
      left:=x1;
     
      x2:=trunc((strtoint(copy(fdate_fin,7,255))-FAnnee_debut)*Echelle);
      if x2>parent.width then x2:=parent.width;
      Width:=x2-x1;
     
      case fVerticale of
           Haut        : Top:=(fNumero_chronologie-1)*Height;
           Milieu_haut : Top:=(parent.Height div 2)-(fNumero_chronologie)*Height;
           Centre      : begin
                           if fNumero_chronologie mod 2=0 then
                              begin
                                Top:=(parent.Height div 2)-((fNumero_chronologie div 2))*Height;
                              end                           else
                              begin
                                Top:=(parent.Height div 2)+(fNumero_chronologie div 2)*Height;
                              end;
                         end;
           Milieu_bas  : Top:=(parent.Height div 2)+(fNumero_chronologie-1)*Height;
           Bas         : Top:=parent.Height-(fNumero_chronologie)*Height;
           Haut_et_bas : begin
                           if fNumero_chronologie mod 2=0 then
                              begin
                                Top:=((fNumero_chronologie div 2)-1)*Height;           // haut
                              end                           else
                              begin
                                Top:=parent.Height-((fNumero_chronologie div 2)+1)*Height; // bas
                              end;
                         end;
      end
    end;
     
     
    end.

  2. #2
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 387
    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 387
    Points : 2 999
    Points
    2 999
    Par défaut
    il est où ce type Positionnement ???

  3. #3
    Membre expert
    Avatar de e-ric
    Homme Profil pro
    Apprenti chat, bienfaiteur de tritons et autres bestioles
    Inscrit en
    Mars 2002
    Messages
    1 556
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Apprenti chat, bienfaiteur de tritons et autres bestioles

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 556
    Points : 3 927
    Points
    3 927
    Par défaut
    Salut

    N'aurais-tu pas deux types énumérés Pos_verticale et Positionnement qui comporte la même constante Haut par hasard ?

    Si tel est le cas, renomme tes constantes avec un préfixe spécifique de chaque type
    - Haut -> posHaut pour le type Positionnement
    - Haut -> pvHaut pour le type Pos_verticale

    Et fais pareil pour les autres constantes.

    @+

    M E N S . A G I T A T . M O L E M
    Debian 64bit, Lazarus + FPC -> n'oubliez pas de consulter les FAQ Delphi et Pascal ainsi que les cours et tutoriels Delphi et Pascal

    "La théorie, c'est quand on sait tout, mais que rien ne marche. La pratique, c'est quand tout marche, mais qu'on ne sait pas pourquoi. En informatique, la théorie et la pratique sont réunies: rien ne marche et on ne sait pas pourquoi!".
    Mais Emmanuel Kant disait aussi : "La théorie sans la pratique est inutile, la pratique sans la théorie est aveugle."

  4. #4
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    Je ne comprends pas bien aussi

    le type au début était "positionnement" et la propriété "position". Vu que j'avais des erreurs j'ai changé les noms par "pos_verticale" et "verticale".

    J'ai fais une recherche je ne trouve pas de texte égale à "positionnement" dans le code de mon objet

    Dans la compile de l'objet, tout est conforme (ma propriété égale à Verticale)

  5. #5
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    En mettant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    type
        Pos_verticale = (pos_Haut,pos_Bas,pos_Milieu_haut,pos_Milieu_bas,pos_Centre,pos_Haut_et_bas);
    Ca marche. Pourquoi ? je ne comprends pas. Bas haut ... ne sont pas des mots réservés pourtant

    Merci à vous

  6. #6
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 387
    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 387
    Points : 2 999
    Points
    2 999
    Par défaut
    construire le projet plutôt que le compiler. Il doit y avoir un fichier dcu qui traine dans un coin

  7. #7
    Membre expert
    Avatar de e-ric
    Homme Profil pro
    Apprenti chat, bienfaiteur de tritons et autres bestioles
    Inscrit en
    Mars 2002
    Messages
    1 556
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Apprenti chat, bienfaiteur de tritons et autres bestioles

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 556
    Points : 3 927
    Points
    3 927
    Par défaut
    Ca marche. Pourquoi ? je ne comprends pas. Bas haut ... ne sont pas des mots réservés pourtant
    Sans doute un conflit de noms, 2 constantes homonymes accessibles dans ton code, le compilo a identifier le mauvais type.

    J'ai fais une recherche je ne trouve pas de texte égale à "positionnement" dans le code de mon objet
    Vérifie si tu n'utilises pas des paquets spécifiques ou des unités qui seraient accessibles via les chemins d'accès des bibliothèques.

    Enfin, passe le topic en résolu.

    M E N S . A G I T A T . M O L E M
    Debian 64bit, Lazarus + FPC -> n'oubliez pas de consulter les FAQ Delphi et Pascal ainsi que les cours et tutoriels Delphi et Pascal

    "La théorie, c'est quand on sait tout, mais que rien ne marche. La pratique, c'est quand tout marche, mais qu'on ne sait pas pourquoi. En informatique, la théorie et la pratique sont réunies: rien ne marche et on ne sait pas pourquoi!".
    Mais Emmanuel Kant disait aussi : "La théorie sans la pratique est inutile, la pratique sans la théorie est aveugle."

Discussions similaires

  1. script qui marche pas...
    Par jpg dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 20/10/2004, 14h19
  2. requete(jointure 2 tables) qui marche pas
    Par DaxTaz dans le forum Langage SQL
    Réponses: 3
    Dernier message: 01/06/2004, 17h50
  3. une comparaison qui marche pas.
    Par gandf dans le forum C++Builder
    Réponses: 7
    Dernier message: 16/02/2004, 15h59
  4. [LG]Split qui marche pas
    Par macluvitch dans le forum Langage
    Réponses: 3
    Dernier message: 30/11/2003, 18h19
  5. Sysdate qui marche pas ??
    Par StouffR dans le forum Langage SQL
    Réponses: 4
    Dernier message: 28/08/2002, 13h23

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