-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTOBJECT.INC
154 lines (135 loc) · 3.35 KB
/
TOBJECT.INC
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{ Copyright 2015 Jerome Shidel }
(*
This project and related files are subject to either the terms
specified in the included LICENSE.TXT file or the GNU GPLv2.0.
*)
{ --- TObject --- }
{$IFDEF INTERFACE}
const
class_TObject : TObjectClass = 'TObject';
type
PObject = ^TObject;
TObject = object
private
{$IFDEF STRINGPTRS}
PNameID : PString;
{$ELSE}
FNameID : String[StringMax];
{$ENDIF}
public { protected }
Parent : PObject;
FFreeOnDestroy : boolean;
procedure SetNameID ( AValue : String ); virtual;
function GetFreeOnDestroy : boolean;
procedure SetFreeOnDestroy(AValue : boolean);
function ObjectClass ( AName : String ) : String; virtual;
public
constructor Create(AName : String);
destructor Destroy; virtual;
function GetNameID : String;
function GetPathID : String;
function GetClassID : String;
function IsChild(AObject : PObject) : boolean;
function IsChildOf(AObject : PObject) : boolean;
function ClassOf( AClass : String ) : boolean;
end;
{$ENDIF}
{$IFDEF IMPLEMENTATION}
function TObject.ObjectClass(AName : String) : String;
begin
ObjectClass := class_TObject;
end;
constructor TObject.Create;
begin
MemCheck(0);
{$IFDEF STRINGPTRS}
PNameID := StrPtr(AName);
{$ELSE}
FNameID := AName;
{$ENDIF}
Parent := nil;
FFreeOnDestroy := True;
{$IFDEF DEVLOG_CREATE}
if GetClassID <> class_TListItem then
WriteLog('Create ' + GetClassID + ' ' + GetPathID );
{$IFDEF DEVLOG_CREATEINDENT}
if GetClassID <> class_TListItem then LogInc;
{$ENDIF}
{$ENDIF}
end;
destructor TObject.Destroy;
begin
MemCheck(0);
{$IFDEF DEVLOG_CREATE}
{$IFDEF DEVLOG_CREATEINDENT}
if GetClassID <> class_TListItem then LogDec;
{$ENDIF}
if GetClassID <> class_TListItem then
WriteLog('Destroy ' + GetClassID + ' ' + GetPathID);
{$ENDIF}
{$IFDEF STRINGPTRS}
FreeStr(PNameID);
{$ENDIF}
end;
function TObject.GetFreeOnDestroy : boolean;
begin
GetFreeOnDestroy := FFreeOnDestroy;
end;
function TObject.GetNameID : String;
begin
{$IFDEF STRINGPTRS}
if Assigned(PNameID) then
GetNameID := PtrStr(PNameID)
else
GetNameID := '';
{$ELSE}
GetNameID := FNameID;
{$ENDIF}
end;
function TObject.GetPathID : String;
begin
if Assigned(Parent) then
GetPathID := Parent^.GetPathID + '.' + GetNameID
else
GetPathID := GetNameID;
end;
procedure TObject.SetNameID ( AValue : String );
begin
{$IFDEF STRINGPTRS}
if Assigned(PNameID) then begin
if PtrStr(PNameID) = AValue then exit;
FreeStr(PNameID);
end;
PNameID := StrPtr(AValue);
{$ELSE}
FNameID := AValue;
{$ENDIF}
end;
function TObject.GetClassID : String;
begin
GetClassID := ObjectClass('');
end;
procedure TObject.SetFreeOnDestroy(AValue : boolean);
begin
FFreeOnDestroy := AValue;
end;
function TObject.IsChild(AObject : PObject) : boolean;
begin
while Assigned(AObject) and (AObject <> @Self) do
AObject := AObject^.Parent;
IsChild := AObject = @Self;
end;
function TObject.IsChildOf(AObject : PObject) : boolean;
var
Temp : PObject;
begin
Temp := @Self;
while Assigned(AObject) and (AObject <> Temp) do
Temp := Temp^.Parent;
IsChildOf := AObject = Temp;
end;
function TObject.ClassOf( AClass : String ) : boolean;
begin
ClassOf := ObjectClass(AClass) = AClass;
end;
{$ENDIF}