Spring4D use of predicates

Hi All,
The compiler complains as follows:
“…There is no overloaded version of ‘First’ that can be called with these arguments”
but I can’t see what is wrong. I could not find an example of the proper use of the ‘First’ predicate anywhere.

I am trying to retrieve the first instance IDesignerProperty where ‘Name’ equals the test value.

{property Enum: IEnumerable<IDesignerProperty> read GetEnum;}

var  LDProp: IDesignerProperty;

LDProp := ADictionary.Dict[LCtrl.QualifiedClassName].Properties.Enum.First(
function(AProp: IDesignerProperty): boolean
begin
  Result := (AProp.Name = 'test');
end);

Thanks, Gerard Hook

I submitted a bug about an error message like this. If it’s the same case, it’s extremely unhelpful.

I think you might find that you need to specifically add the < IDesignerProperty > part in your code, rather than try to have it type-inferred by the compiler.

ie .Enum<xyz>.First( );

If that’s it .. it’s a bit upsetting that we can’t always have nice things.

Thanks Paul,

Currently I feel that I must have a big hole in my predicate knowledge as I couldn’t get it to work in another case recently with Spring4D.

I’ve read Nick Hodges books on repeat and Spring4D is a must. The DI Container usage is a game changer.

I’ve just remembered that Spring4D includes a heap of demo source. I’ll have a closer look there.

Also, my Spring4D version is 1.2.2 so I should check if this should be updated.

Gerard Hook

You should most definitely update to 2.0.1 - there have been a lot of improvements since v1 (and more coming). I use Spring4D a lot (I no longer use the rtl collections) including the container - once you have written an application using dependency injection it’s hard to go back to no using it.

FWIW, a predicate is typically just a function that returns a boolean value - it looks more complicated than it should be in delphi due to the lack of lambda style syntax.

I know this is a very late response but for future readers: there is a const missing from the predicate parameter.

3 Likes