blob: 3d09177cafe28b8861f4a317839c5015d8592bce (
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
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
155
|
{$mode objfpc}
program test05;
uses
SysUtils;
type
QObjectH = class(TObject) end;
QWidgetH = class(QObjectH) end;
IQbase = interface(IUnknown)
end;
TQBase = class(TInterfacedObject,IQBase)
protected
fQHandle : TObject;
function GetQHandle : TObject;
procedure SetQHandle(Value : TObject);
public
property QHandle : TObject read GetQHandle write SetQHandle;
end;
IQObject = interface(IQBase)
function GetQHandle : QObjectH;
property QHandle : QObjectH read GetQHandle;
end;
TQObject = class(TQBase, IQObject)
protected
function GetQHandle : QObjectH; overload;
procedure SetQHandle(Value:QObjectH);
public
property QHandle : QObjectH read GetQHandle write SetQHandle;
constructor CreateWrapper;
Constructor Create(name: PAnsiChar); overload;
end;
IQWidget = interface(IQObject)
function GetQHandle : QWidgetH;
property QHandle : QWidgetH read GetQHandle;
function Width: Integer;
end;
TQWidget = class(TQObject, IQWidget)
protected
function GetQHandle : QWidgetH; overload;
procedure SetQHandle(Value:QWidgetH);
public
property QHandle : QWidgetH read GetQHandle write SetQHandle;
constructor CreateWrapper;
Constructor Create(name: PAnsiChar); overload;
function Width: Integer;
end;
function TQObject.GetQHandle : QObjectH;
begin
if Self <> nil then Result := QObjectH(fQHandle)
else Result := nil;
end;
procedure TQObject.SetQHandle(Value : QObjectH);
begin
fQHandle := TObject(Value);
end;
constructor TQObject.CreateWrapper;
begin
inherited Create;
end;
Constructor TQObject.Create(name: PAnsiChar);
begin
CreateWrapper;
end;
function TQBase.GetQHandle : TObject;
begin
Result := fQHandle
end;
procedure TQBase.SetQHandle(Value : TObject);
begin
fQHandle:=Value;
end;
function TQWidget.GetQHandle : QWidgetH;
begin
write(' entering TQWidget.GetQHandle ...');
if Self <> nil then Result := QWidgetH(fQHandle)
else Result := nil;
writeln('...leaving entering TQWidget.GetQHandle');
end;
procedure TQWidget.SetQHandle(Value : QWidgetH);
begin
fQHandle := TObject(Value);
end;
constructor TQWidget.CreateWrapper;
begin
write(' entering TQWidget.CreateWrapper ...');
inherited Create;
writeln('...leaving TQWidget.CreateWrapper');
end;
Constructor TQWidget.Create(name: PAnsiChar);
begin
write('entering TQWidget.Create ...');
CreateWrapper;
writeln('... leaving TQWidget.Create');
end;
function TQWidget.Width: Integer;
begin
write(' entering TQWidget.Width...');
Result:=123;
writeln('...leaving TQWidget.Width');
end;
function GetWidget : IQWidget;
begin
Result := TQWidget.CreateWrapper;
end;
begin
writeln('GetWidget.Width (123)?:',GetWidget.Width);
if GetWidget.Width<>123 then
begin
writeln('error');
halt(1);
end;
end.
|