à tous
Je ne suis pas encore treè habile dans la création de composants. Voici celui qui me pose problème.
En suivant les conseils avisés de Okaryn j'ai déterminé que le problème venait de ClientWidth (flèche rouge). Si je mets Width tout seul le composant s'affiche, mais je ne peux pas changer la largeur du champ Ville. Si je mets ClientWidth, la compilation et l'intallation se passent bien, mais le composant est inutilisable : message le composant '' n'a pas de fenêtre parent. Je ne vois pas comment récupérer la largeur du composant, laquelle me sert à déterminer la largeur du champ ville
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 unit DBCodePostVille; interface uses SysUtils, Classes, Controls, StdCtrls, DBCtrls, DB, Graphics, Types, ZAbstractRODataset, ZDataset, ZAbstractDataset, ZSqlUpdate, ZConnection; type TDBCodePostVille = class(TCustomGroupBox) private { Déclarations privées } Code_Postal : TDBComboBox; // Liste de choix depuis une table Ville : TDBComboBox; // Liste de choix depuis une table procedure AgencementComposant; protected { Déclarations protégées } procedure BoundsChanged; procedure DoExit; override; public { Déclarations publiques } constructor Create(AOwner: TComponent); override; destructor Destroy; override; published { Déclarations publiées } // La cible property DataCible : TDataSource read GetDataCible write SetDataCible; property DataCibleField_CP : string read GetCibleField_CP write SetCibleField_CP; property DataCibleField_Ville : string read GetCibleField_Ville write SetCibleField_Ville; // La source property DataSource : TDataSource read GetDataSource write SetDataSource; property DataSourceField_CP : string read GetSourceField_CP write SetSourceField_CP; property DataSourceField_Ville : string read GetSourceField_Ville write SetSourceField_Ville; end; procedure Register; implementation uses Variants, Dialogs; procedure Register; begin RegisterComponents('Perso_VCL', [TDBCodePostVille]); end; { TDBCodePostVille } procedure TDBCodePostVille.AgencementComposant; begin Code_Postal.Left := 2; //8; Code_Postal.Top := 20; //24; Code_Postal.Width := 89; Ville.Left := Code_Postal.Left + Code_Postal.Width + 2; Ville.Top := Code_Postal.Top; Ville.Width := ClientWidth - Code_Postal.Width - 2; <======== end; procedure TDBCodePostVille.BoundsChanged; begin if Assigned(Code_Postal) and Assigned(Ville) then AgencementComposant; end; constructor TDBCodePostVille.Create(AOwner: TComponent); begin inherited Create(AOwner); Caption := 'Code postal / Ville : '; Width := 345; ParentFont := True; Height := 49; Code_Postal := TDBComboBox.Create(Self); Code_Postal.Parent := Self; Code_Postal.CharCase := ecUpperCase; Code_Postal.Sorted := True; Code_Postal.OnEnter := DBComboBox_CP_OnEnter; Ville := TDBComboBox.Create(Self); Ville.Parent := Self; Ville.CharCase := ecUpperCase; Ville.Sorted := True; Ville.OnEnter := DBComboBox_VILLE_OnEnter; FDataSource_CP := TFieldDataLink.Create; FDataSource_CP.Control := Self; FDataSource_VILLE := TFieldDataLink.Create; FDataSource_VILLE.Control := Self; AgencementComposant; end
d'avance pour toute suggestion
Partager