blob: 76c1370624bb2f24b8f5644376b91218c64c702c (
plain)
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
|
{ %norun}
{ %OPT=-Sew -vw}
{$MODE delphi}
type
TTestRec1 = record
A, B: Integer;
end;
TTestRec2 = record
A, B: Integer;
class operator Explicit(const rec: TTestRec2): ShortString;
end;
TTestRec3 = record
A, B: Integer;
function ToString: ShortString;
end;
TTestRec4 = record
A: Integer;
function ToString: ShortString;
var B: Integer;
end;
class operator TTestRec2.Explicit(const rec: TTestRec2): ShortString;
begin
with rec do WriteStr(Result, A, ':', B);
end;
function TTestRec3.ToString: ShortString;
begin
Result := ShortString(TTestRec2(Self));
end;
function TTestRec4.ToString: ShortString;
begin
Result := ShortString(TTestRec2(Self));
end;
const
r1: TTestRec1 = (A: 1; B: 2);
r2: TTestRec2 = (A: 3; B: 4);
r3: TTestRec3 = (A: 5; B: 6);
r4: TTestRec3 = (A: 7; B: 8);
begin
Writeln(ShortString(r2));
Writeln(SizeOf(TTestRec1) = SizeOf(TTestRec2));
Writeln(ShortString(TTestRec2(r1)));
Writeln(r3.ToString);
Writeln(r4.ToString);
end.
|