Bonjour à tous,

voilà mon problème :

je veux créer un composant dérivé de TPanel me permettant une personnalisation de son dessin.
J'avais dans un premier temps créé de nouvelles propriétés published mais j'ai vite été fatigué de les chercher dans l'editeur de propriétés parmi celles qui existent dejà.
J'ai donc voulu créer un groupe qui contiendrait toutes les nouvelles options, comme par expl la propriété Option du stringgrid qui va contenir goEditing etc...

Pour ce faire j'ai créé une classe avec mes différentes options (types variés), elle-même déclarée comme propriété dans ma classe dérivée de TPanel.

Tout va bien, mes options sont bien regroupées dans un même intitulé dans l'editeur, une fois le composant installé.

Ce que je ne comprends pas, c'est que lorsque je modifie une de ces options la procedure write de la propriété concernée de la classe des options est bien exécutée alors que la procedure write de la classe parent (le Tpanel) ne l'est pas. Du coup je ne peux pas demander la mise à jour du dessin.

En attendant j'ai trouvé une solution en utilisant une variable contenant le parent, mais je suis sur qu'il y a plus propre (et ça ne me dit pas ce que j'ai raté )

Voici le code simplifié (pas toutes les propriétés), pour plus de clarté :
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
 
unit PanelBG;
 
 
interface
 
uses
  SysUtils, windows, Classes, Controls, ExtCtrls, Graphics,dialogs ;
 
  type
 
    TPBGoptions = class
    private
      FParent:Tobject; // <--- solution intermédiaire
      FColorStart: Tcolor;
      FColorEnd: Tcolor;
      FColorMid: Tcolor;
 
 
      procedure SetColorEnd(val: Tcolor);
      procedure SetColorMid(val: Tcolor);
      procedure SetColorStart(val: Tcolor);
 
 
    public
      constructor Create(AOwner: TComponent);
 
    published
      property ColorStart: Tcolor read FColorStart write SetColorStart ;
      property ColorMid: Tcolor read FColorMid write SetColorMid;
      property ColorEnd: Tcolor read FColorEnd write SetColorEnd ;
 
  end;
 
    TPanelBG = class(TPanel)
    private
      FPBGoptions: TPBGoptions;
      procedure SetPBGoptions (val: TPBGoptions);
    Protected
      procedure Paint; override;
    Public
      constructor Create(AOwner: TComponent); override;
    published
      property BGOptions:TPBGoptions read FPBGoptions write SetPBGoptions ;// <---- cette procédure n'est pas exécutée !
    end;
 
procedure Register;
 
 
implementation
 
 
 
procedure Register;
begin
  RegisterComponents('Samples', [TPanelBG]);
end;
 
 
{ TPBGoptions }
constructor TPBGoptions.Create(AOwner: TComponent);
begin
  FParent:=Aowner; <--- solution intermédiaire
  FColorStart:=clwhite;
  FColorMid:=clSilver;
  FColorEnd:=clBlack;
end;
 
procedure TPBGoptions.SetColorStart(val: Tcolor);
begin
  if val<>FColorStart then begin
    FColorStart:=val;
    TPanelBG(FParent).invalidate;    // <--- solution intermédiaire
  end;
end;
procedure TPBGoptions.SetColorMid(val: Tcolor);
begin
  if val<>FColorMid then begin
    FColorMid:=val;
    TPanelBG(FParent).invalidate;    //<--- solution intermédiaire
  end;
end;
procedure TPBGoptions.SetColorEnd(val: Tcolor);
begin
  if val<>FColorEnd then begin
    FColorEnd:=val;
    TPanelBG(FParent).invalidate;    //<--- solution intermédiaire
  end;
end;
 
 
{ TPanelBG }
 
constructor TPanelBG.Create(AOwner: TComponent);
begin
  inherited;
  DoubleBuffered:=true;
  FPBGoptions:=TPBGoptions.Create(self);
  with FPBGoptions do begin
 
    ColorStart:=clSilver;
    ColorMid:=clgray;
    ColorEnd:=clwhite;
 
  end;
 
end;
 
procedure TPanelBG.Paint;
var p1,fo:integer;
    bmpT:TBitmap;
begin
  ...
 
 
end;
 
procedure TPanelBG.SetPBGoptions(val: TPBGoptions); // <---- cette procédure n'est pas exécutée !
begin
 
  if val<>FPBGoptions then begin
    FPBGoptions:=val;
 
    invalidate;
    Repaint;
  end;
end;
 
 
end.

merci pour votre aide,
David