Salut à tous.
J'ai une classe de base
deux classe descendant TChildAClass et tChildBClass qui sont similaire (pour le test)
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 TAncestorClass = Class private FErrorNum: TErrorType; FInternalNum: Integer; FErrorDesc: String; FonError: TNotifyEvent; procedure SetErrorDesc(const Value: String); procedure SetErrorNum(const Value: TErrorType); procedure SetInternalNum(const Value: Integer); procedure SetonError(const Value: TNotifyEvent); protected procedure DoError; property OnError : TNotifyEvent read FOnError write SetOnError; published property InternalNum : Integer read FInternalNum write SetInternalNum; property ErrorNum : TErrorType read FErrorNum write SetErrorNum; property ErrorDesc : String read FErrorDesc write SetErrorDesc; end; Implementation procedure TAncestorClass.DoError; begin If Assigned(FOnError) then FOnError(Self); end; procedure TAncestorClass.SetErrorDesc(const Value: String); begin If FErrorDesc <> Value then FErrorDesc := Value; end; procedure TAncestorClass.SetErrorNum(const Value: TErrorType); begin If FErrorNum <> Value then begin FErrorNum := Value; if FErrorNum = etError then DoError; end; end; procedure TAncestorClass.SetInternalNum(const Value: Integer); begin If FInternalNum <> Value then FInternalNum := Value; end; procedure TAncestorClass.SetOnError(const Value: TNotifyEvent); begin FOnError := Value; end;
Une autre classe heritant de TAnestorClass et qui instancie les 2 autres classes
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 TChildBClass = Class(TAncestorClass) private FStrOne: String; procedure SetStrOne(const Value: String); published property StrOne : String read FStrOne write SetStrOne; property OnError; end; implementation procedure TChildAClass.SetStrOne(const Value: String); begin if FStrOne <> Value then begin FStrOne := Value; if Length(FStrOne) > 15 then begin ErrorDesc := 'Length string out of range in class : '+Self.ClassName; ErrorNum := etError; FStrOne := ''; end; end; end;
La question :
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 TMixClass = Class(TAncestorClass) private FChildA: TChildAClass; FChildB: TChildBClass; procedure SetChildA(const Value: TChildAClass); procedure SetChildB(const Value: TChildBClass); published property ChildA : TChildAClass read FChildA write SetChildA; property ChildB : TChildBClass read FChildB write SetChildB; property OnError; public constructor create; destructor destroy; Override; end; implementation constructor TMixClass.create; begin Inherited Create; ChildA := TChildAClass.Create; ChildB := TChildBClass.Create; end; destructor TMixClass.destroy; begin ChildA.Free; ChildB.Free; inherited; end; procedure TMixClass.SetChildA(const Value: TChildAClass); begin FChildA := Value; end; procedure TMixClass.SetChildB(const Value: TChildBClass); begin FChildB := Value; end;
Comment implementer l'event OnError au niveau de TMixClass pour que les OnError de ChildA et ChildB soit intercepté.
Merci
Partager