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.