Sign in Join
Wiki copytemporary

As: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-The [[Operator|operator]] `as` performs a conditional [[Typecast|typecast]]. The word `as` is a [[Reserved word|reserved word]] in [[Mode Delphi|{$mode Delphi}]] and [[Mode ObjFPC|{$mode objFPC}]].
1+The [[Operator|operator]] `as` performs a conditional [[Typecast|typecast]]. The word `as` is a [[Reserved word|reserved word]] in [[Mode Delphi|`{$mode Delphi}`]] and [[Mode ObjFPC|`{$mode objFPC}`]].
22
33## operation
44
5-`as` requires a [[Class|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:
6-
7-``` pascal
8- super(child)
9- if not assigned(child) and_then not child is super then
10- begin
11- raise exception.create(sErrInvalidTypecast);
12- end;
5+`as` requires a [[Class|`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:
136```
7+super(child)
8+ if not assigned(child) and_then not child is super then
9+ begin
10+ raise exception.create(sErrInvalidTypecast);
11+ end;
12+```
1413
15-> **Warning:** Typecasting a [[Nil|nil pointer]] will not raise an exception.
14+[![Warning-icon.png](/wiki-images/b/b2/Warning-icon.png)](</File:Warning-icon.png>)
1615
17-However, trying to de-reference `nil` by attempting to access an attribute or method *will* cause a [[runtime error|RTE]].
16+**Warning:** Typecasting a [[Nil|`nil` pointer]] will not raise an exception.
1817
18+However, trying to de-reference `nil` by attempting to access an attribute or method _will_ cause a [[runtime error|RTE]].
19+
1920## application
2021
21-`as` ensures a typecast is legit.
22+`as` ensures a typecast is legit.
2223
23-`as` is one of the operators that can not be [[Operator overloading|overloaded]].
24+`as` is one of the operators that can not be [[Operator overloading|overloaded]].
2425
2526## see also
2627
27-- [[Is|is]]
28+ * [[Is|`is`]]
2829
2930---
30-*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](/wiki-contact).*
31+*From the Free Pascal wiki, page "As", as the Internet Archive kept it on 2024-03-04. 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](/wiki-contact).*

Back to history