-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSTRING.PAS
78 lines (63 loc) · 1.45 KB
/
USTRING.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
{
ustring Unit
TObject wrapper for pascal strings
2022 LRT
}
unit
ustring;
interface
uses
uexc, uclasses, types, locale, uobject;
type
PString = ^TString;
TString = object (TObject)
public
constructor init;
constructor initWithValue(value: string);
destructor done; virtual;
procedure setValue(value: string);
function getValue: string;
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_value: ^string;
end;
implementation
{ TString public }
constructor TString.init;
begin
inherited init;
_value := nil;
end;
constructor TString.initWithValue(value: string);
begin
inherited init;
_value := nil;
setValue(value);
end;
destructor TString.done;
begin
if _value <> nil then FreeMem(_value, length(_value^) + 1);
inherited done;
end;
procedure TString.setValue(value: string);
begin
if _value <> nil then FreeMem(_value, length(_value^) + 1);
GetMem(_value, length(value) + 1);
Move(value, _value^, length(value) + 1);
end;
function TString.getValue: string;
begin
getValue := _value^;
end;
function TString.getClassName: string;
begin
getClassName := 'TString';
end;
function TString.getClassId: word;
begin
getClassId := C_CLASS_ID_String;
end;
{ TString private }
{ Other }
end.