From Lazarus wiki
Revision as of 16:23, 6 August 2022 by Kai Burghardt (talk | contribs) (resolve Category: Pages using deprecated enclose attributes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr)

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


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:

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

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.


as ensures a typecast is legit.

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

see also