-
Notifications
You must be signed in to change notification settings - Fork 2
/
oopExample2.nim
60 lines (44 loc) · 1.23 KB
/
oopExample2.nim
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
49
50
51
52
53
54
55
56
57
58
59
60
import macros, oopHelper
declClass TComponent:
var
FOwner* : TComponent
method getRight(): int = 0
proc initialize* () {.inline.} =
echo "init TComponent"
proc create(AOwner: TComponent) {.constructor.} =
self.FOwner = AOwner
declClass TControl, TComponent:
var
FLeft, FTop, FWidth, FHeight: int
method getRight(): int {.override.} =
return self.FLeft + self.FWidth
method Foo(a, b, c: int): int =
return a + b + c
proc initialize () {.inline.} =
echo "init TControl"
initialize(super(self))
self.FLeft = 0
self.FTop = 0
self.FWidth = 100
self.FHeight = 50
declClass TWinControl, TControl:
var
FHandle : int
Name* : string
method Foo(a: int, b: int, c: int): int {.override.} =
return 2 * a + b - c
proc initialize () {.inline.} =
echo "init TWinControl"
initialize(super(self))
self.Name = "Nimrod"
self.FHandle = 1234
var a = TComponent.create(nil)
var b = TControl.create(a)
echo a.repr
echo b.FOwner == a
var c = TWinControl.create(a)
echo c.Name, " ", c.FOwner == a
c.Name = "MyName"
echo c.getClassName, " ",
var t: TComponent = c
echo t.getClassName(), " ", t.getRight(), " ", t of TControl, " ", a of TWinControl