Hello,

What is an explanation why the first code is not good but the second one is good?
At least, the first code is three times as shorter and clear.
Second code seems to be taken from Delphi 7 where the first one doesn't works.

On 28/11/2015 12:00, fpc-pascal-requ...@lists.freepascal.org wrote:
>if Animal is IBarkable then (Animal as IBarkable).Bark;
This is not good usage of Interfaces. Use the interface variable instead.

var
   intf: IBarkable
begin
   if Supports(Animal, IBarbable, intf) then
   begin
     intf.Bark;
     // you can continue here using intf further without casting
   end;
--
Regards,
Serguei
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to