[fpc-devel] [Suggestion] Enumeration range-check intrinsic

Ben Grasset operator97 at gmail.com
Wed Jul 3 18:00:26 CEST 2019


On Tue, Jul 2, 2019 at 7:38 PM Ondrej Pokorny <lazarus at kluug.net> wrote:

> A good real-word example is the cast from a pointer:
>
> program Project1;
> uses Classes;
> var
>    Value: TPersistent;
>    P: Pointer;
> begin
>    P := TObject.Create;
>    Value := TPersistent(P);
>    if Value is TPersistent then
>      Writeln('Value is TPersistent')
>    else
>      Writeln('Value is not TPersistent');
>    Readln;
> end.
>

In general, assuming P was a pointer initialized elsewhere (meaning you
really didn't know what it was), why wouldn't you just write this:

  if TObject(P) is TPersistent then
    Writeln('Value is TPersistent')
  else
    Writeln('Value is not TPersistent');
  Readln;

Behaves as you'd expect, and doesn't require an additional variable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190703/afe9356a/attachment.html>


More information about the fpc-devel mailing list