TArgs with Generics

38 views
Skip to first unread message

gshelt...@gmail.com

unread,
Sep 9, 2024, 9:46:36 AM9/9/24
to Spring4D
I get "types of actual and formal var parameters must be identical" on 
TArgs.Items[0].IsAny<TList<TDate>>,

with this field and  method:
 FConflictedDates : TList<TDate>;

procedure GetConflictedDates(var DateList: TList<TDate>; const Route : String);

This call:
GetConflictedDates(FConflictedDates,
      cbxRoute.Items[cbxRoute.ItemIndex].Caption);

and this test:

Assert.WillNotRaise(
      procedure
      begin
        lViewModel.Received(Times.Once)
          .GetConflictedDates(
            TArgs.Items[0].IsAny<TList<TDate>>,
            TArgs.Items[1].IsEqual<String>('1-A'));
      end, EMockException);

Any help would be appreciated

gshelt...@gmail.com

unread,
Sep 9, 2024, 12:50:44 PM9/9/24
to Spring4D
I changed to Spring.Collections

FConflictedDates : IList<TDate>;

And all relevant places. Code compiles and works fine just can't get the test working. Still same error   "types of actual and formal var parameters must be identical"

Stefan Glienke

unread,
Sep 9, 2024, 1:48:19 PM9/9/24
to Spring4D
Arg matcher does not require directly indexing the parameters, it does that under the hood.
When it's a var parameter (is that needed? This only is necessary if the method inside might construct the list) it needs to be slightly different

For your method you need to write:

          .GetConflictedDates(
            Arg.Ref<IList<TDate>>.IsAny,
            Arg.IsEqual<string>('1-A'));

Wrapping it into Assert.WillNotRaise is also not necessary IMO but that's a DUnitX thing I guess.

gshelt...@gmail.com

unread,
Sep 9, 2024, 5:48:39 PM9/9/24
to Spring4D
Thank You for the quick response. That did the trick.

So the class function Ref<T>: TArg<T>; overload; static; inline;

Should be used for any var parameters?

BTW somewhere along the way when I was learning I got into the  Assert.WillNotRaise habit. Just tried it without, much simpler :) 

Reply all
Reply to author
Forward
0 new messages