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

Sven Barth pascaldragon at googlemail.com
Wed Jul 3 18:40:58 CEST 2019


Ben Grasset <operator97 at gmail.com> schrieb am Mi., 3. Juli 2019, 18:00:

> 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.
>

The code by Ondrej was to prove a point not to have the shortest variant.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190703/63849271/attachment.html>


More information about the fpc-devel mailing list