-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtdelphiinterfacechain1.pp
More file actions
64 lines (54 loc) · 1.16 KB
/
Copy pathtdelphiinterfacechain1.pp
File metadata and controls
64 lines (54 loc) · 1.16 KB
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
program tdelphiinterfacechain1;
{$ifdef FPC}
{$mode delphi}
{$endif}
uses
SysUtils;
type
IBase = interface
['{D2A4477D-D860-443E-90BF-0EC510A0537D}']
function GetText: string;
property Text: string read GetText;
end;
IDerived = interface(IBase)
['{FD663604-48E8-4294-9D4D-CB34E2A4A49E}']
function CopyValue(AValue: Integer): IDerived;
end;
TProbe = class(TInterfacedObject, IBase, IDerived)
private
FValue: Integer;
public
constructor Create(AValue: Integer);
function CopyValue(AValue: Integer): IDerived;
function GetText: string;
end;
constructor TProbe.Create(AValue: Integer);
begin
inherited Create;
FValue := AValue;
end;
function TProbe.CopyValue(AValue: Integer): IDerived;
begin
Result := TProbe.Create(AValue);
end;
function TProbe.GetText: string;
begin
Result := IntToStr(FValue);
end;
function NewProbe(AValue: Integer): IDerived;
begin
Result := TProbe.Create(AValue);
end;
var
D: IDerived;
begin
D := NewProbe(1);
If D.CopyValue(2).Text <> '2' then
Halt(10);
If D.CopyValue(3).Text <> '3' then
Halt(11);
If D.Text <> '1' then
Halt(12);
D := nil;
WriteLn('OK');
end.