-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUOBJECT.PAS
135 lines (113 loc) · 2.93 KB
/
UOBJECT.PAS
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{
UObject Unit
Base class for all objects in the library
2022 LRT
}
unit
UObject;
interface
uses
uclasses, types;
type
PObject = ^TObject;
TCompareFunc = function(value: pointer; obj: PObject): ECompareResult;
PObjectMessage = ^TObjectMessage;
TObject = object
public
constructor init;
destructor done; virtual;
procedure retain;
procedure release;
procedure receiveMessage(msg: PObjectMessage); virtual;
procedure sendMessage(opcode: word; target: PObject);
procedure sendMessageWithData(opcode: word; target: PObject; payload: pointer; size: word);
procedure setDelegate(obj: PObject);
function getDelegate: PObject;
function compare(value: PObject): ECompareResult; virtual;
function getClassName: string; virtual;
function getClassId: word; virtual;
function getRetainCount: word;
private
_retainCount: word;
_delegate: PObject;
end;
{ a simple representation of a message sent between two objects }
TObjectMessage = packed record
opcode: word;
sender: PObject;
target: PObject;
payload: pointer;
size: word;
end;
implementation
constructor TObject.init;
begin
_retainCount := 1;
_delegate := nil;
end;
destructor TObject.done;
begin
end;
procedure TObject.retain;
begin
inc(_retainCount);
end;
procedure TObject.release;
var
this: PObject;
begin
dec(_retainCount);
if _retainCount = 0 then
begin
this := @self;
dispose(this, done);
end;
end;
procedure TObject.receiveMessage(msg: PObjectMessage); begin end;
procedure TObject.sendMessage(opcode: word; target: PObject);
var
msg: TObjectMessage;
begin
if target = nil then exit;
msg.opcode := opcode;
msg.target := target;
msg.sender := @self;
target^.receiveMessage(@msg);
end;
procedure TObject.sendMessageWithData(opcode: word; target: PObject; payload: pointer; size: word);
var
msg: TObjectMessage;
begin
if target = nil then exit;
msg.opcode := opcode;
msg.target := target;
msg.sender := @self;
msg.payload := payload;
msg.size := size;
target^.receiveMessage(@msg);
end;
procedure TObject.setDelegate(obj: PObject);
begin
_delegate := obj;
end;
function TObject.getDelegate: PObject;
begin
getDelegate := _delegate;
end;
function TObject.compare(value: PObject): ECompareResult;
begin
compare := ECompareUndefined;
end;
function TObject.getClassName: string;
begin
getClassName := 'TObject';
end;
function TObject.getClassId: word;
begin
getClassId := C_CLASS_ID_OBJECT;
end;
function TObject.getRetainCount: word;
begin
getRetainCount := _retainCount;
end;
end.