@@ -130,6 +130,8 @@ TAny = record
130130 class operator Implicit(const value : TAny): string; overload;
131131 end ;
132132
133+ procedure CleanupArguments (const arguments: TArray<TValue>);
134+
133135implementation
134136
135137uses
@@ -167,20 +169,17 @@ function GetIndexString(const v: TValue): Integer;
167169
168170function GetIndexObject (const v: TValue): Integer;
169171begin
170- Result := v.AsType<TIndexWrapper>.fIndex;
171- v.AsType<TIndexWrapper>.Free;
172+ Result := TIndexWrapper(TValueData(v).FAsObject).fIndex;
172173end ;
173174
174175function GetIndexInterface (const v: TValue): Integer;
175176begin
176- Result := (v.AsType<IInterface> as TIndexWrapper).fIndex;
177- PValue(@v)^ := TValue.Empty;
177+ Result := (PInterface(TValueData(v).FValueData.GetReferenceToRawData)^ as TIndexWrapper).fIndex;
178178end ;
179179
180180function GetIndexPointer (const v: TValue): Integer;
181181begin
182- Result := v.AsType<TIndexWrapper>.fIndex;
183- v.AsType<TIndexWrapper>.Free;
182+ Result := Integer(TValueData(v).FAsPointer);
184183end ;
185184
186185function GetIndexRecord (const v: TValue): Integer;
@@ -255,7 +254,7 @@ procedure SetIndexString(typeInfo: PTypeInfo; index: Integer; var Result);
255254procedure SetIndexObject (typeInfo: PTypeInfo; // FI:O804
256255 index: Integer; var Result);
257256begin
258- TObject(PPointer(@ Result)^ ) := TIndexWrapper.Create(index);
257+ TObject(Result) := TIndexWrapper.Create(index);
259258end ;
260259
261260procedure SetIndexInterface (typeInfo: PTypeInfo; // FI:O804
@@ -267,7 +266,7 @@ procedure SetIndexInterface(typeInfo: PTypeInfo; //FI:O804
267266procedure SetIndexPointer (typeInfo: PTypeInfo; // FI:O804
268267 index: Integer; var Result);
269268begin
270- Pointer (Result) := TIndexWrapper.Create( index) ;
269+ NativeInt (Result) := index;
271270end ;
272271
273272procedure SetIndexRecord (typeInfo: PTypeInfo; index: Integer; var Result);
@@ -301,6 +300,18 @@ procedure SetIndexVariant(typeInfo: PTypeInfo; //FI:O804
301300 PVariant(@Result)^ := index;
302301end ;
303302
303+ procedure CleanupArguments (const arguments: TArray<TValue>);
304+ var
305+ i: Integer;
306+ begin
307+ for i := 0 to High(arguments) do
308+ if arguments[i].IsType(TypeInfo(TIndexWrapper)) then
309+ begin
310+ TObject(TValueData(arguments[i]).FAsObject).Free;
311+ TValueData(arguments[i]).FAsObject := nil ;
312+ end ;
313+ end ;
314+
304315
305316{ $REGION 'TMatcherFactory'}
306317
@@ -375,7 +386,7 @@ class function TMatcherFactory.GetIndex(const v: TValue): Integer;
375386 GetIndexFail, GetIndexOrdinal, GetIndexObject, GetIndexFail, GetIndexString,
376387 GetIndexString, GetIndexString, GetIndexVariant, GetIndexArray, GetIndexRecord,
377388 GetIndexInterface, GetIndexOrdinal, GetIndexArray, GetIndexString, GetIndexFail,
378- GetIndexPointer , GetIndexFail { $IF Declared(tkMRecord)} , GetIndexFail{ $IFEND} );
389+ GetIndexObject , GetIndexFail { $IF Declared(tkMRecord)} , GetIndexFail{ $IFEND} );
379390begin
380391 Result := Handlers[TValueData(v).FTypeInfo.Kind](v) - 1 ;
381392end ;
@@ -387,7 +398,7 @@ class procedure TMatcherFactory.SetIndex(typeInfo: PTypeInfo; index: Integer; va
387398 SetIndexFail, SetIndexOrdinal, SetIndexObject, SetIndexFail, SetIndexString,
388399 SetIndexString, SetIndexString, SetIndexVariant, SetIndexArray, SetIndexRecord,
389400 SetIndexInterface, SetIndexOrdinal, SetIndexArray, SetIndexString, SetIndexFail,
390- SetIndexPointer , SetIndexFail { $IF Declared(tkMRecord)} , SetIndexFail{ $IFEND} );
401+ SetIndexObject , SetIndexFail { $IF Declared(tkMRecord)} , SetIndexFail{ $IFEND} );
391402begin
392403 Handlers[typeInfo.Kind](typeInfo, index + 1 , Result);
393404end ;
@@ -469,7 +480,7 @@ class function TArg.IsEqual<T>(const value: T): T;
469480 Result := TMatcherFactory.CreateMatcher<T>(
470481 function(const arg: TValue): Boolean
471482 begin
472- Result := arg.Convert<T> .Equals(TValue.From<T>( value ));
483+ Result := arg.Convert(TypeInfo(T)) .Equals(TValue.From(@ value , TypeInfo(T) ));
473484 end );
474485end ;
475486
0 commit comments