Je suis en D7 et j'ai besoin de modifier la valeur d'une propriété d'un objet.
J'utilise donc le RTTI mais étrangement quand je vais lire une propriété je la trouve bien mais le IsPublishedProp renvoie toujours False.
Exemple (voir la ligne 55 IsPublishedProp) de mon code :
Une idée ??
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 unit Unit1; interface uses Classes, Controls, Forms, StdCtrls,TypInfo; type TForm1 = class(TForm) btn1: TButton; procedure btn1Click(Sender: TObject); private FsTest: string; procedure SetsTest(const Value: string); { Déclarations privées } public { Déclarations publiques } published property sTest: string read FsTest write SetsTest; end; TOClient = class(TObject) private FCL_ABOID: integer; procedure SetCL_ABOID(const Value: integer); { Déclarations privées } protected { Déclarations protégées } public { Déclarations publiques } published property CL_ABOID: integer read FCL_ABOID write SetCL_ABOID; end; var Form1: TForm1; OCl : TOClient; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject); var iBcl,iNb : Integer; ListeProprietes: TPropList; sNameTemp : string; DonneePropriete: TPropInfo; begin OCL := TOClient.Create; iNb := GetPropList(TypeInfo(TOClient), tkAny, @ListeProprietes); for iBcl := 0 to iNb-1 do begin DonneePropriete := ListeProprietes[iBcl]^; sNameTemp := DonneePropriete.Name; if Pos('CL_ABOID',sNameTemp)>0 then if IsPublishedProp(OCL,sNameTemp) then SetOrdProp(OCL,sNameTemp,Longint(0)) ; end; end; procedure TForm1.SetsTest(const Value: string); begin FsTest := Value; end; { TOClient } procedure TOClient.SetCL_ABOID(const Value: integer); begin FCL_ABOID := Value; end; end.
Partager