si ce serait aussi simple....
je trouve rien depuis un bout et pourtant je cherche vrm......Comment on peut cree un variable pendant l'execution du programme...a la guise de l'utilisateur sur le clic d'un simple bouton?
Merci!
Version imprimable
si ce serait aussi simple....
je trouve rien depuis un bout et pourtant je cherche vrm......Comment on peut cree un variable pendant l'execution du programme...a la guise de l'utilisateur sur le clic d'un simple bouton?
Merci!
En tenant à jour un tableau associatif de variants ;)
A toi d'adapter selon tes besoins... ;)Code:
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 type TVarsDynamiques = class private FNames : TStrings; FVariables : array of Variant; function GetVariables(Name : string) : Variant; procedure SetVariables(Name : string; Value : Variant); public constructor Create; destructor Destroy; override; property Variables[Name : string] : Variant read GetVariables write SetVariables; default; end; implementation constructor TVarsDynamiques.Create; begin inherited; FNames := THashedStringList.Create; end; destructor TVarsDynamiques.Destroy; begin SetLength(FVariables, 0); FNames.Free; inherited; end; function TVarsDynamiques.GetVariables(Name : string) : Variant; var Index : integer; begin Index := FNames.IndexOf(Name); if Index < 0 then Result := Unassigned else Result := FVariables[Index]; end; procedure TVarsDynamiques.SetVariables(Name : string; Value : Variant); var Index : integer; begin Index := FNames.IndexOf(Name); if Index >= 0 then FVariables[Index] := Value else begin Index := FNames.Add(Name); SetLength(FVariables, Length(FVariables)+1); FVariables[Index] := Value; end; end;