-
Notifications
You must be signed in to change notification settings - Fork 0
/
uDBHamsterOle.pas
246 lines (210 loc) · 6 KB
/
uDBHamsterOle.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
unit uDBHamsterOle;
interface
uses VirtualTrees, uDBBase, Classes, ActiveX, ComObj {,OleAuto},
Forms;
type
tDBHamsterOle = class(tDBBase)
private
ham : OLEVariant;
fGroup : String;
fGroupIdx : Integer;
protected
function getGroupName: String; override;
public
procedure ReadFolderList(res : tVirtualStringTree;
RootNode : PVirtualNode; BasePath : String;
PathStrings : tList); override;
procedure GetArticle (ArtNum : integer; var ResArt : String; var ResSize : Integer); override;
function GetOverList(const ArtList: toArtList; vPath: PString; var Res: tStringList; progr : tProgressXOver) : Boolean; override;
function GetAllOverList(vPath: PString; var Res: tStringList; progr: tProgressXOver) : Boolean; override;
function Count : longint; override;
function Max : longint; override;
function Min : longint; override;
function Open(Path : String): boolean; override;
procedure Close; override;
end;
implementation
{ tDBNNTP }
uses SysUtils;
function tDBHamsterOle.Open(Path: String): boolean;
var vPath, s1, s2 : String;
begin
Result := false;
if pos('<<', Path)>0 then begin
fGroup := trim(copy(Path, pos('<<', Path)+2, length(Path)));
vPath := copy(Path, 1, pos('<<', Path)-1);
end else begin
fGroup := '';
vPath := Path;
end;
CoInitialize( nil ); //???
// create 'Hamster.App'-object
try
ham := CreateOleObject( vPath ); //'Hamster.App'
if (fGroup <> '') then begin
fGroupIdx := ham.NewsGrpOpen(fGroup)
end;
Result := true;
except
on E:Exception do begin
s1 := 'ERROR: ' + E.Message;
s2 := 'Object "'+vPath+'" could not be created!';
Application.MessageBox(
PChar(s1),
PChar(s2),
1 );
exit;
end;
end;
end;
function tDBHamsterOle.getGroupName: String;
begin
Result := fGroup;
end;
procedure tDBHamsterOle.ReadFolderList(res: tVirtualStringTree;
RootNode: PVirtualNode; BasePath: String; PathStrings: tList);
var
max, idx, i : Integer;
name : String;
EntryNode: PVirtualNode;
temData: pTreeData;
begin
if open(BasePath) then try
max := ham.NewsGrpCount;
for idx := 0 to max-1 do begin
name := ham.NewsGrpName(idx);
EntryNode := res.AddChild(RootNode);
temData := res.GetNodeData(EntryNode);
with temData^ do begin
imgidx := 31; //2: Pull or not
DB := tDBHamsterOle;
Caption := name;
new(Path);
PathStrings.Add(Path);
Path^ := BasePath + '<<' + Caption;
i := ham.NewsGrpOpen(name);
Count := ham.NewsArtCount(i);
ham.NewsGrpClose(i);
end;
end;
finally close end
end;
function tDBHamsterOle.GetAllOverList(vPath: PString;
var Res: tStringList; progr : tProgressXOver) : Boolean;
var j, i, mi, ma: Integer;
temTreeData: POverview;
line: string;
OverRes: TStrings;
linesList : TStrings;
cancel : Boolean;
begin
OverRes := TStringList.Create;
lineslist := TStringList.create;
try
Res.Sorted := true;
{
s := WriteReadLn('XOVER '+IntToStr(Min)+'-'+IntToStr(Max));
if Copy(s, 1, 1) <> '2' then begin
Result := inherited GetOverList(ArtList, vPath, Res);
Exit;
end;
}
mi := Min;
ma := Max;
i := mi;
while (i<ma) do begin
linesList.Text := ham.NewsGrpXOver(fGroupIdx, i, i+99);
//Progressbar
if (Assigned(progr)) then
progr(fGroup, mi, ma, i, cancel);
if cancel then break;
j := 0;
repeat
line := linesList[j];
ComputeXOverLine(line, OverRes);
//Progressbar
if (Assigned(progr)) then
progr(fGroup, Min, Max, StrToIntDef(OverRes[0], -1), cancel);
if cancel then break;
temTreeData := ComputeOverOfXOver(OverRes, vPath, tDBBaseClass(self.ClassType));
Res.AddObject(temTreeData^.Mid, TObject(temTreeData));
inc(j);
until (j>=linesList.count);
//Nachgeschoben
if (cancel) then break;
i := i + 100;
end;
finally
linesList.free;
OverRes.Free;
end;
Result := not Cancel
end;
function tDBHamsterOle.GetOverList(const ArtList: toArtList; vPath: PString;
var Res: tStringList; progr : tProgressXOver) : Boolean;
var i : Integer;
temTreeData: POverview;
line: string;
OverRes: TStrings;
linesList : TStrings;
cancel : Boolean;
begin
OverRes := TStringList.Create;
lineslist := TStringList.create;
try
Res.Sorted := true;
{
s := WriteReadLn('XOVER '+IntToStr(Min)+'-'+IntToStr(Max));
if Copy(s, 1, 1) <> '2' then begin
Result := inherited GetOverList(ArtList, vPath, Res);
Exit;
end;
}
for i := 0 to length(ArtList)-1 do begin
line := ham.NewsArtXOver(fGroupIdx, ArtList[i]);
//Progressbar
if (Assigned(progr)) then
progr(fGroup, 0, length(ArtList), i, cancel);
if cancel then break;
ComputeXOverLine(line, OverRes);
temTreeData := ComputeOverOfXOver(OverRes, vPath, tDBBaseClass(self.ClassType));
Res.AddObject(temTreeData^.Mid, TObject(temTreeData));
end;
finally
linesList.free;
OverRes.Free;
end;
Result := not Cancel;
end;
procedure tDBHamsterOle.GetArticle(ArtNum: integer; var ResArt: String;
var ResSize: Integer);
begin
ResArt := '';
ResSize := -1;
//if (not Assigned(ham)) then exit;
ResArt := ham.NewsArtText(fGroupIdx, ArtNum);
ResSize := length(ResArt);
end;
function tDBHamsterOle.Count: longint;
begin
Result := ham.NewsArtCount(fGroupIdx)
end;
function tDBHamsterOle.Max: longint;
begin
Result := ham.NewsArtNoMax(fGroupIdx)
end;
function tDBHamsterOle.Min: longint;
begin
Result := ham.NewsArtNoMin(fGroupIdx)
end;
procedure tDBHamsterOle.Close;
begin
if (fGroup<>'') then ham.NewsGrpClose(fGroupIdx);
fGroup := '';
// release 'Hamster.App'-object
if (VarIsEmpty(ham)) then begin
ham := Unassigned;
CoUninitialize;
end
end;
end.