-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathmyeventdata.pas
143 lines (118 loc) · 4.33 KB
/
myeventdata.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
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
unit myeventdata;
{
IMyEventData:
The data object for each event. For this particular demo, it also
includes the method to generate a random event for creating test data.
Written by Joachim Marder, Sanjay Kanade
}
interface
type
IMyEventData = interface
['{0CDF0FE6-6B98-4541-B644-729513B41044}']
procedure SetDate(adate: TDateTime); stdcall;
procedure SetName(aName: string); stdcall;
procedure SetAmount(anAmount: currency); stdcall;
function GetDate: TDateTime; stdcall;
function GetName: string; stdcall;
function GetAmount: currency; stdcall;
//Generates a fictitious event for the demo
procedure initializeRandom; stdcall;
//properties for raw data
//date of event
property date: TDateTime read GetDate write SetDate;
//name of event
property name: string read GetName write SetName;
//amount collected in the event
property amount: currency read GetAmount write SetAmount;
function isStarEvent: boolean; stdcall;
end;
TMyEventData = class(TInterfacedObject, IMyEventData)
private
fdate: TDateTime;
fname: string;
famount: currency;
protected
procedure SetDate(adate: TDateTime); stdcall;
procedure SetName(aName: string); stdcall;
procedure SetAmount(anAmount: currency); stdcall;
function GetDate: TDateTime; stdcall;
function GetName: string; stdcall;
function GetAmount: currency; stdcall;
public
constructor Create; virtual;
destructor Destroy; override;
procedure initializeRandom; virtual; stdcall;
property date: TDateTime read GetDate write SetDate;
property name: string read GetName write SetName;
property amount: currency read GetAmount write SetAmount;
function isStarEvent: boolean; virtual; stdcall;
end;
implementation
uses System.DateUtils, System.SysUtils;
//----------------------------------------------------------------------------------------------------------------------
constructor TMyEventData.Create;
begin
inherited;
//initialize
famount := -1;
end;
//----------------------------------------------------------------------------------------------------------------------
destructor TMyEventData.Destroy;
begin
//do cleanup
//To test whether auto cleanup is done
//showmessage('Cleaning up '+fname);
inherited;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyEventData.SetDate(adate: TDateTime); stdcall;
begin
fdate := adate;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyEventData.GetDate: TDateTime; stdcall;
begin
result := fdate;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyEventData.SetName(aName: string); stdcall;
begin
fname := aName;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyEventData.GetName: string; stdcall;
begin
result := fname;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyEventData.SetAmount(anAmount: currency); stdcall;
begin
famount := anAmount;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyEventData.GetAmount: currency; stdcall;
begin
result := famount;
end;
//----------------------------------------------------------------------------------------------------------------------
function getRandomDate: TDateTime;
begin
result := Today;
result := IncDay(result, -random(365));
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyEventData.initializeRandom;
begin
fdate := getRandomDate;
fname := Format('Charity event %d', [random(9999)+1]);
famount := random(500000);
while famount < 50000 do
famount := random(500000);
end;
//----------------------------------------------------------------------------------------------------------------------
//An event is a star event if it collected an amount > 300,000.
function TMyEventData.isStarEvent: boolean;
begin
result := famount > 300000;
end;
end.