Sign in Join
Wiki copytemporary

Revision 1 of 3, by Kai Burghardt on 8-6-2022. The page as it is now.

As

The operator as performs a conditional typecast. The word as is a reserved word in {$mode Delphi} and {$mode objFPC}.

operation

as requires a class or (COM) interface as the first argument and a class or interface reference as the second. The expression child as super is equivalent to the expression and statement:

pascal
    super(child)
    if not assigned(child) and_then not child is super then
    begin
        raise exception.create(sErrInvalidTypecast);
    end;

Warning: Typecasting a nil pointer will not raise an exception.

However, trying to de-reference nil by attempting to access an attribute or method will cause a RTE.

application

as ensures a typecast is legit.

as is one of the operators that can not be overloaded.

see also


From the Free Pascal wiki, page "As", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.