Skip to content

[Coding in Delphi] Chapter 4.9 Predicates: Sample code not compiling #3

@BastianTeufel-GTR

Description

@BastianTeufel-GTR

Hi,

I'm just digging through your book and found a small mistake in one (or two, because it's twice the same function call) of the printed examples:

var
  IsLessThan10: TPredicate<integer>;
begin
  IsLessThan10 := function(const aValue: integer): Boolean
      begin
        Result := aValue < 10;
      end;
…
end;

Per definition of the TPredicate type, it accepts no const values. It throws an incompatible Type error
When changing the call to like that it works:

var
  IsLessThan10: TPredicate<integer>;
begin
  IsLessThan10 := function(aValue: integer): Boolean
      begin
        Result := aValue < 10;
      end;
…
end;

If you're considering to publish an updated version of the book you might consider to change the latter 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions