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

Composants FMX Delphi Discussion :

Création composant FMX


Sujet :

Composants FMX Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 32
    Par défaut Création composant FMX
    Bonjour,

    je tente de créer un composant FMX en me basant sur un composant que j'ai créée il y a quelques années avec delphi 4. Mon composant est constitué d'un conteneur (un panel ou layout) et contient lui-même d'autres composants: un Spinbox pour sélectionner des valeurs et des Label pour afficher des calculs en fonction des valeurs sélectionnées.

    Mon problème est le suivant: lorsque je place le composant sur une fiche, les composants contenus dans le composant sont créées en double (SpinBox et Labels).

    Voici le code du composant:
    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
     
    unit ContainerCalculPrixQteTotal;
     
    interface
     
    uses
      System.SysUtils, System.Classes, FMX.Edit, FMX.Types, FMX.Controls, FMX.StdCtrls, FMX.Layouts;
     
    type
      TContainerCalculPrixQteTotal = class(TPanel)
      private
        { Déclarations privées }
        FCode: String;
        FNumTouche: String;
        FActive: Boolean;
        FLibelle: String;
        FPrix: Currency;
        FQte : integer;
        FLabMontant : TLabel;
        FlabEgal : TLabel;
        FLabMulti : TLabel;
        FLabTotal : TLabel;
        FOnchange: TNotifyEvent;
        FOnkeyDown: TKeyEvent;
        function GetQte: Integer;
        procedure SetPrix(MPrix: Currency);
        procedure ChangeMontant(Sender: TObject);
    //    procedure CompOnKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);
        procedure SetQte(MQte: Integer);
        procedure ChangeQte(Sender: TObject);
     
      protected
        { Déclarations protégées }
        FSpinBox : TSpinBox;
     
      public
        { Déclarations publiques }
         constructor Create(AOwner: TComponent);override;
         destructor Destroy; override;
      published
        { Déclarations publiées }
        property Qte : integer read GetQte write SetQte;
        property MPrix : Currency read FPrix write SetPrix;
        property OnChange: TNotifyEvent read FOnchange write FOnchange;
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
      RegisterComponents('MesComp', [TContainerCalculPrixQteTotal]);
    end;
     
     
    constructor TContainerCalculPrixQteTotal.Create(AOwner: TComponent);
    var
     MY : Integer;
    begin
      MY:=10;
      Inherited;
    //  Text:=' ';
      width:=360;
      FSpinBox := TSpinBox.Create(Self);
      FSpinBox.Parent := Self;
      FSpinBox.Position.Y:=MY;
      FSpinBox.Position.X:=20;
      FSpinBox.Font.Size:=14;
      FSpinBox.Font.Family:='Times New Roman';
      //FSpinBox.Font.Style:=[fsBold];
      FSpinBox.Width := 70;
      FSpinBox.Height := 22;
      FSpinBox.Visible := True;
      FSpinBox.OnChange:=ChangeMontant; //ChangeQte;
      //FSpinBox.OnKeyDown:=CompOnKeyDown(self,key,Shift);
     
     
      FlabEgal:=TLabel.Create(self);
      FlabEgal.Parent := Self;
      FlabEgal.position.y:=MY;
      FlabEgal.Font.Size:=14;
      FlabEgal.font.family:='Times New Roman';
      //FlabEgal.Font.Style:=[fsBold];
      FlabEgal.Visible:=true;
      FlabEgal.TextAlign:=TTextAlign.taTrailing;
      FlabEgal.position.X:=215;
      FlabEgal.Text:='=';
      FLabEgal.Width:=16;
     
      FLabMulti:=TLabel.Create(self);
      FLabMulti.Parent := Self;
      FLabMulti.position.y:=MY;
      FLabMulti.Font.Size:=14;
      FLabMulti.font.family:='Times New Roman';
      //FLabMulti.Font.Style:=[fsBold];
      FLabMulti.Visible:=true;
      FLabMulti.TextAlign:=TTextAlign.taTrailing;
      FLabMulti.position.X:=100;
      FLabMulti.Text:='X';
      FLabMulti.Width:=16;
     
      FLabTotal:=TLabel.Create(self);
      FLabTotal.Parent := Self;
      FLabTotal.position.y:=MY;
      FLabTotal.Font.Size:=14;
      FLabTotal.font.family:='Times New Roman';
      //FLabTotal.Font.Style:=[fsBold];
      FLabTotal.Visible:=true;
      FLabTotal.Width:=84;
      FLabTotal.TextAlign:=TTextAlign.taTrailing;;
      FLabTotal.position.X:=264;
      FLabTotal.Text:=FloatToStrF(FPrix,ffcurrency,12,2);
    end;
     
    destructor TContainerCalculPrixQteTotal.Destroy;
    begin
      FLabTotal.Free;
      FLabMulti.Free;
      FSpinBox.Free;
      inherited;
    end;
     
     
     
    procedure TContainerCalculPrixQteTotal.SetPrix(MPrix: Currency);
    begin
      FPrix := MPrix;
      //FlabEgal.text:=FloatToStrF(MPrix,ffcurrency,12,2);
      FLabMontant.text:=FloatToStrF(MPrix,ffcurrency,12,2);
    end;
     
    procedure TContainerCalculPrixQteTotal.ChangeMontant(Sender: TObject);
    var
     MMontant : currency;
    begin
        FLabTotal.text:=FloatToStrF(FPrix*FSpinBox.Value,ffcurrency,12,2);
    end;
     
    function TContainerCalculPrixQteTotal.GetQte: Integer;
    begin
     Result := round(FSpinBox.Value);
    end;
     
    procedure TContainerCalculPrixQteTotal.SetQte(MQte: Integer);
    begin
     FQte:=MQte;
     FSpinBox.Value:=MQte;
    end;
     
    procedure TContainerCalculPrixQteTotal.ChangeQte(Sender: TObject);
    begin
     FQte:=round(FSpinBox.Value);
    end;
     
     
    end.
    Merci d'avance.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 32
    Par défaut
    J'ai trouvé la solution. En effet, Chaque composants créé doit avoir sa propriété Stored définie sur False et sa propriété Locked définie sur True.

    "Si la propriété Stored n'est pas désactivée, les sous-composants seront créés de façon redondante lors du chargement." Aide Embarcadero.

    Donc, comme je l'avait remarqué, les composants étaient créés en plusieurs exemplaires, mais ils n'avaient pas les même propriétés. Par exemple, les SpinBox ne répondaient pas à l'événement OnChange.

    Ce qui donne:
    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
    constructor TContainerCalculPrixQteTotal.Create(AOwner: TComponent);
    var
     MY : Integer;
    begin
      MY:=10;
      Inherited;
      width:=360;
      FSpinBox := TSpinBox.Create(Self);
      FSpinBox.Parent := Self;
      FSpinBox.Position.Y:=MY;
      FSpinBox.Position.X:=20;
      FSpinBox.Font.Size:=14;
      FSpinBox.Font.Family:='Times New Roman';
      FSpinBox.Width := 70;
      FSpinBox.Height := 22;
      FSpinBox.Visible := True;
      FSpinBox.OnChange:=ChangeMontant; //ChangeQte;
      FSpinBox.Stored:=False;
      FSpinBox.Locked:=True;
    
      FLabMontant:=TLabel.Create(self);
      FLabMontant.Parent := Self;
      FLabMontant.position.y:=MY;
      FLabMontant.Position.X:=130;
      FLabMontant.Font.Size:=14;
      FLabMontant.Font.Family:='Times New Roman';
      FLabMontant.Visible:=true;
      FLabMontant.Width:=84;
      FLabMontant.Text:='0,00 €';
      FLabMontant.Stored:=False;
      FLabMontant.Locked:=True;
    
      FlabEgal:=TLabel.Create(self);
      FlabEgal.Parent := Self;
      FlabEgal.position.y:=MY;
      FlabEgal.Font.Size:=14;
      FlabEgal.font.family:='Times New Roman';
      FlabEgal.Visible:=true;
      FlabEgal.TextAlign:=TTextAlign.taTrailing;
      FlabEgal.position.X:=215;
      FlabEgal.Text:='=';
      FLabEgal.Width:=16;
      FLabEgal.Stored:=False;
      FLabEgal.Locked:=True;
    
      FLabMulti:=TLabel.Create(self);
      FLabMulti.Parent := Self;
      FLabMulti.position.y:=MY;
      FLabMulti.Font.Size:=14;
      FLabMulti.font.family:='Times New Roman';
      FLabMulti.Visible:=true;
      FLabMulti.TextAlign:=TTextAlign.taTrailing;
      FLabMulti.position.X:=100;
      FLabMulti.Text:='X';
      FLabMulti.Width:=16;
      FLabMulti.Stored:=False;
      FLabMulti.Locked:=True;
    
      FLabTotal:=TLabel.Create(self);
      FLabTotal.Parent := Self;
      FLabTotal.position.y:=MY;
      FLabTotal.Font.Size:=14;
      FLabTotal.font.family:='Times New Roman';
      FLabTotal.Visible:=true;
      FLabTotal.Width:=84;
      FLabTotal.TextAlign:=TTextAlign.taTrailing;;
      FLabTotal.position.X:=264;
      FLabTotal.Text:=FloatToStrF(FPrix,ffcurrency,12,2);
      FLabTotal.Stored:=False;
      FLabTotal.Locked:=True;
    
    end;
    En espérant que cela permette à d'autres de ne pas perdre des heures en recherche. Bienvenue dans le monde merveilleux de Firemonkey et de ses petites surprise (je continue à croire qu'en maîtrisant les subtilités, il s'agit d'un outil très puissant).

    Bonne journée et bon code….

Discussions similaires

  1. Problème création composant conteneur
    Par nek_kro_kvlt dans le forum Delphi
    Réponses: 5
    Dernier message: 29/07/2007, 00h09
  2. Création Composant Delphi 2005 win32
    Par woow dans le forum Composants VCL
    Réponses: 9
    Dernier message: 20/07/2006, 13h35
  3. Cherche exemple création composant visuel
    Par bertin dans le forum Composants VCL
    Réponses: 1
    Dernier message: 02/08/2005, 16h14
  4. [C#] OnPaint(PaintEventArgs e) sur création Composant
    Par pc152 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 26/08/2004, 16h13
  5. Création composant et BD
    Par gibet_b dans le forum Composants VCL
    Réponses: 6
    Dernier message: 07/07/2004, 15h03

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