-
Notifications
You must be signed in to change notification settings - Fork 0
/
uHamDLL.pas
155 lines (131 loc) · 3.45 KB
/
uHamDLL.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
144
145
146
147
148
149
150
151
152
153
154
155
unit uHamDLL;
interface
uses KWKHamster_TLB, sysutils;
type
eNotInitialized = class(Exception);
eFileNotFound = class(Exception);
tDLLUse = class
private
fDLL : clsHamster;
fGroup : string;
fPath : String;
fOpen : Boolean;
function GoToArt(Nummer : Integer) : Boolean;
public
procedure SetGroup(group : string);
function GetPosting(ArtNummer : Integer) : String;
function GetAgentFormatPosting(ArtNo: Integer; var ArtTime : longint): String;
procedure SetPath(Path : string);
procedure SetDATAdat(FileName : string);
function GetDateTime(ArtNummer : Integer) : String;
Constructor Create;
Destructor Destroy; override;
end;
implementation
constructor tDLLUse.Create;
begin
inherited;
fDll := coClsHamster.Create;
fOpen := false;
fPath := '';
fGroup := '';
end;
procedure tDLLUse.SetDATAdat(FileName: string);
begin
if fOpen then
fDll.CloseConnection;
fOpen := false;
if (filename='') then begin
fPath := '';
fGroup := '';
exit;
end;
if not fileexists(filename) then
raise eFileNotFound.Create('Leerer Filename wurde übergeben oder das File wurde nicht gefunden!');
fDLL.OpenConnection(filename);
filename := ExtractFilePath(Filename);
if filename[length(filename)]='\' then
system.delete(filename,length(filename),1);
fPath := copy(filename,1,LastDelimiter('\',filename));
fGroup := copy(filename,LastDelimiter('\',filename)+1,length(filename));
fOpen := true;
end;
procedure tDLLUse.SetPath(Path: string);
begin
if Path[length(Path)]<>'\' then
Path := Path + '\';
if fPath='' then
fPath := Path
else begin
fPath := Path;
if fOpen then
fDll.CloseConnection;
fOpen := false;
if fPath = '' then exit;
fDLL.OpenConnection(fPath + fGroup + '\data.dat');
fOpen := true;
end;
end;
procedure tDLLUse.SetGroup(group: string);
begin
if fOpen then
fDll.CloseConnection;
fOpen := false;
if Group = '' then begin
fGroup := '';
exit;
end;
if Group[1]='\' then
Group := copy(Group,2,length(Group));
fGroup := Group;
fDLL.OpenConnection(fPath + fGroup + '\data.dat');
fOpen := true;
end;
function tDLLUse.GoToArt(Nummer: Integer) : Boolean;
begin
Result := false;
if not fOpen then
raise eNotInitialized.Create('Keine Gruppe ausgewählt!');
if Nummer>0 then begin
fDll.AbsolutePosition := Nummer;
Result := true;
end;
end;
const
GroundDate = 25569; // =EncodeDate(1970,1,1)
function tDLLUse.GetAgentFormatPosting(ArtNo: Integer; var ArtTime : longint): String;
var s : string;
begin
if GoToArt(ArtNo) then begin
s := fDll.posting.DateTime;
if s<>'' then
ArtTime := round((StrToDateTime(s) - GroundDate) * 86400)
else
ArtTime := GroundDate;
Result := fDLL.Posting.Subject + #9
+ fDLL.Posting.Name
+ ' <' + fDLL.Posting.EMail + '>' + #9
+ IntToStr(ArtTime) + #13#10
+ fDLL.posting.Header + #13#10#13#10
+ fDLL.posting.Body;
end;
end;
function tDLLUse.GetDateTime(ArtNummer: Integer): String;
begin
GoToArt(ArtNummer);
Result := fDLL.posting.DateTime;
end;
function tDLLUse.GetPosting(ArtNummer: Integer) : string;
begin
GoToArt(ArtNummer);
Result := fDLL.posting.Header + #13#10#13#10 + fDLL.posting.Body;
end;
destructor tDLLUse.Destroy;
begin
if fOpen then
fDll.CloseConnection;
// fDll._Release;
//ToDo: Überprüfen, ob nicht benötigt
inherited;
end;
end.