Sign in Join
Wiki copytemporary

As: what changed

Revision 2 to 3. 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-super(child)
8- if not assigned(child) and_then not child is super then
9- begin
10- raise exception.create(sErrInvalidTypecast);
11- end;
12-```
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
14-[![Warning-icon.png](/wiki-images/b/b2/Warning-icon.png)](</File:Warning-icon.png>)
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;
13+```
1514
16-**Warning:** Typecasting a [[Nil|`nil` pointer]] will not raise an exception.
15+> **Warning:** Typecasting a [[Nil|nil pointer]] will not raise an exception.
1716
18-However, trying to de-reference `nil` by attempting to access an attribute or method _will_ cause a [[runtime error|RTE]].
17+However, trying to de-reference `nil` by attempting to access an attribute or method *will* cause a [[runtime error|RTE]].
1918
2019## application
2120
22-`as` ensures a typecast is legit.
21+`as` ensures a typecast is legit.
2322
24-`as` is one of the operators that can not be [[Operator overloading|overloaded]].
23+`as` is one of the operators that can not be [[Operator overloading|overloaded]].
2524
2625## see also
2726
28- * [[Is|`is`]]
27+- [[Is|is]]
2928
3029---
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).*
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).*

Back to history