Bonjour,
Je cherche un moyen d'automatiser la copie d'objet afin que lors de la création d'un objet enfant, je puisse utiliser un objet parent pour l'initialiser.
Je m'explique : j'ai un objet TParametreChamp de type TPersistent et son enfant TParametreChampEntier. Leurs prototypes se présentent comme ceci :
Code Delphi : 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 type TTypeParametre = (tpAlphabetique = 1, tpMemo = 2, tpTelephone = 3, tpCourriel = 4, tpDate = 5, tpBoolean = 6); TParametreChamp = class(TPersistent) private FID : Int64; FLibelle : string; FTypeChamp: TTypeParametre; FPosition : Int32; FLock : Boolean; public constructor Create(); published property ID: Int64 read FID write FID; property Libelle: string read FLibelle write FLibelle; property TypeChamp: TTypeParametre read FTypeChamp write FTypeChamp; property Position: Int32 read FPosition write FPosition; property Lock: Boolean read FLock write FLock; end; TParametreChampEntier = class(TParametreChamp) private FNomTable : string; FNomChamp : string; FNomTableID : string; FMaitreTable: string; FMaitreChamp: string; public constructor Create(); overload; constructor Create(const AParametreChamp: TParametreChamp); overload; published property NomTable: string read FNomTable write FNomTable; property NomChamp: string read FNomChamp write FNomChamp; property NomTableID: string read FNomTableID write FNomTableID; property MaitreTable: string read FMaitreTable write FMaitreTable; property MaitreChamp: string read FMaitreChamp write FMaitreChamp; end;
Lors de la création de chaque objets, j'initialise le contenu de leurs champs
Code Delphi : 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 { TParametreChamp } constructor TParametreChamp.Create(); begin inherited; FID := 0; FLibelle := ''; FTypeChamp := tpAlphabetique; FPosition := 0; FLock := False; end; { TParametreChampEntier } constructor TParametreChampEntier.Create(); begin inherited; FNomTable := ''; FNomChamp := ''; FNomTableID := ''; FMaitreTable := ''; FMaitreChamp := ''; end; constructor TParametreChampEntier.Create(const AParametreChamp: TParametreChamp); begin Create(); AParametreChamp.AssignTo(TParametreChamp(Self)); end;
Mais lorsque je veux créer un objet TParametreChampEntier à partir d'un TParametreChamp, j'ai une erreur : "EConvertError : Impossible d'affecter TParametreChamp à TParametreChampEntier".
Quelqu'un aurait une idée de méthode, ou dois-je copier les valeurs de tous les champs un par un ?
Merci.
Partager