-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathis_as.lpr
48 lines (39 loc) · 1.01 KB
/
is_as.lpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{$mode objfpc}{$H+}{$J-}
program is_as;
uses
SysUtils;
type
TMyClass = class
procedure MyMethod;
end;
TMyClassDescendant = class(TMyClass)
procedure MyMethodInDescendant;
end;
procedure TMyClass.MyMethod;
begin
WriteLn('MyMethod');
end;
procedure TMyClassDescendant.MyMethodInDescendant;
begin
WriteLn('MyMethodInDescendant');
end;
var
Descendant: TMyClassDescendant;
C: TMyClass;
begin
Descendant := TMyClassDescendant.Create;
try
Descendant.MyMethod;
Descendant.MyMethodInDescendant;
{ Descendant има цялата функционалност, която се очаква от
TMyClass, така че това присвояване е OK }
C := Descendant;
C.MyMethod;
{ Това не може да сработи, тъй като TMyClass не дефинира този метод }
//C.MyMethodInDescendant;
if C is TMyClassDescendant then
(C as TMyClassDescendant).MyMethodInDescendant;
finally
FreeAndNil(Descendant);
end;
end.