2 {*****************************************************************************}
4 { Tnt Delphi Unicode Controls }
5 { http://www.tntware.com/delphicontrols/unicode/ }
8 { Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
10 {*****************************************************************************}
14 {$INCLUDE TntCompilers.inc}
20 {$IFNDEF COMPILER_10_UP}
28 TWideStringsAdapter
= class(TAutoIntfObject
, IStrings
, IWideStringsAdapter
)
30 FStrings
: TWideStrings
;
32 { IWideStringsAdapter }
33 procedure ReferenceStrings(S
: TWideStrings
);
34 procedure ReleaseStrings
;
36 function Get_ControlDefault(Index
: Integer): OleVariant
; safecall;
37 procedure Set_ControlDefault(Index
: Integer; Value
: OleVariant
); safecall;
38 function Count
: Integer; safecall;
39 function Get_Item(Index
: Integer): OleVariant
; safecall;
40 procedure Set_Item(Index
: Integer; Value
: OleVariant
); safecall;
41 procedure Remove(Index
: Integer); safecall;
42 procedure Clear
; safecall;
43 function Add(Item
: OleVariant
): Integer; safecall;
44 function _NewEnum
: IUnknown
; safecall;
46 constructor Create(Strings
: TTntStrings
);
52 Classes
, ActiveX
, Variants
;
54 { TStringsEnumerator }
57 TStringsEnumerator
= class(TContainedObject
, IEnumString
)
59 FIndex
: Integer; // index of next unread string
62 constructor Create(const Strings
: IStrings
);
63 function Next(celt
: Longint; out elt
;
64 pceltFetched
: PLongint
): HResult
; stdcall;
65 function Skip(celt
: Longint): HResult
; stdcall;
66 function Reset
: HResult
; stdcall;
67 function Clone(out enm
: IEnumString
): HResult
; stdcall;
70 constructor TStringsEnumerator
.Create(const Strings
: IStrings
);
72 inherited Create(Strings
);
76 function TStringsEnumerator
.Next(celt
: Longint; out elt
; pceltFetched
: PLongint
): HResult
;
81 while (I
< celt
) and (FIndex
< FStrings
.Count
) do
83 TPointerList(elt
)[I
] := PWideChar(WideString(FStrings
.Item
[FIndex
]));
87 if pceltFetched
<> nil then pceltFetched
^ := I
;
88 if I
= celt
then Result
:= S_OK
else Result
:= S_FALSE
;
91 function TStringsEnumerator
.Skip(celt
: Longint): HResult
;
93 if (FIndex
+ celt
) <= FStrings
.Count
then
100 FIndex
:= FStrings
.Count
;
105 function TStringsEnumerator
.Reset
: HResult
;
111 function TStringsEnumerator
.Clone(out enm
: IEnumString
): HResult
;
114 enm
:= TStringsEnumerator
.Create(FStrings
);
115 TStringsEnumerator(enm
).FIndex
:= FIndex
;
118 Result
:= E_UNEXPECTED
;
122 { TWideStringsAdapter }
124 constructor TWideStringsAdapter
.Create(Strings
: TTntStrings
);
128 OleCheck(LoadRegTypeLib(LIBID_STDVCL
, 4, 0, 0, StdVcl
));
129 inherited Create(StdVcl
, IStrings
);
133 procedure TWideStringsAdapter
.ReferenceStrings(S
: TWideStrings
);
138 procedure TWideStringsAdapter
.ReleaseStrings
;
143 function TWideStringsAdapter
.Get_ControlDefault(Index
: Integer): OleVariant
;
145 Result
:= Get_Item(Index
);
148 procedure TWideStringsAdapter
.Set_ControlDefault(Index
: Integer; Value
: OleVariant
);
150 Set_Item(Index
, Value
);
153 function TWideStringsAdapter
.Count
: Integer;
156 if FStrings
<> nil then Result
:= FStrings
.Count
;
159 function TWideStringsAdapter
.Get_Item(Index
: Integer): OleVariant
;
162 if (FStrings
<> nil) then Result
:= WideString(FStrings
[Index
]);
165 procedure TWideStringsAdapter
.Set_Item(Index
: Integer; Value
: OleVariant
);
167 if (FStrings
<> nil) then FStrings
[Index
] := Value
;
170 procedure TWideStringsAdapter
.Remove(Index
: Integer);
172 if FStrings
<> nil then FStrings
.Delete(Index
);
175 procedure TWideStringsAdapter
.Clear
;
177 if FStrings
<> nil then FStrings
.Clear
;
180 function TWideStringsAdapter
.Add(Item
: OleVariant
): Integer;
183 if FStrings
<> nil then Result
:= FStrings
.Add(Item
);
186 function TWideStringsAdapter
._NewEnum
: IUnknown
;
188 Result
:= TStringsEnumerator
.Create(Self
);