Ben Grasset <operato...@gmail.com> schrieb am Mi., 3. Juli 2019, 18:00:
> On Tue, Jul 2, 2019 at 7:38 PM Ondrej Pokorny <laza...@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 >
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel