-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPLCONST.PAS
382 lines (335 loc) · 10.6 KB
/
APLCONST.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
{$I COMPILER.INC}
unit AplConst;
interface
type
PCustomErrorMessageProc = ^TCustomErrorMessageProc;
PProc = ^TProc;
TCustomErrorMessageProc = function(AErrorCode: integer; var found: boolean): string;
TProc = procedure;
String1 = string[1];
String2 = string[2];
String3 = string[3];
String4 = string[4];
String5 = string[5];
String6 = string[6];
String7 = string[7];
String8 = string[8];
String9 = string[9];
String10 = string[10];
String11 = string[11];
String12 = string[12];
String13 = string[13];
String14 = string[14];
String15 = string[15];
String16 = string[16];
String17 = string[17];
String18 = string[18];
String19 = string[19];
String20 = string[20];
String25 = string[25];
String30 = string[30];
String35 = string[35];
String40 = string[40];
String45 = string[45];
String50 = string[50];
String75 = string[75];
String80 = string[80];
String85 = string[80];
String90 = string[80];
String100 = string[100];
const
HexDigits: string16 = '0123456789ABCDEF';
PointerSize: longint = SizeOf(Pointer);
MaxVarSize = $FFF0;
ecNone = 0;
{ IO Codes }
ecFileNotFound = 101;
ecFileCreateError = 102;
ecFileOpenError = 103;
ecFileReadError = 104;
ecFileWriteError = 105;
ecFileVersionError = 106;
ecFileTypeError = 106;
ecFileInvalid = 107;
ecMouseError = 108;
{ Graphics errors }
ecGraphicsNotSupported = 201;
ecGraphicsDriverError = 202;
ecGraphicsModeNotFound = 203;
ecUnsupportedPaletteFormat = 204;
ecInvalidPalette = 205;
{ Memory errors }
ecMemoryReferenceNotFound = 301;
ecInvalidMemoryReference = 302;
ecNotEnoughMemory = 303;
ecInvalidAllocSize = 304;
ecXmsNotInitialized = 305;
ecXmsNotSupported = 306;
ecXmsError = 307;
{ Stream errors }
ecSeekPastStreamEnd = 400;
ecWritePastStreamEnd = 401;
ecReadPastStreamEnd = 402;
ecStreamSeekNotSupported = 403;
ecStreamWriteNotSupported = 404;
ecStreamReadNotSupported = 405;
ecStreamNotOpen = 406;
ecStreamCloseError = 407;
ecStreamOpenError = 408;
ecStreamReadError = 409;
ecStreamWriteError = 410;
ecStreamSeekError = 411;
ecStreamFormatNotSupported = 412;
{ Text errors }
ecTextDriverNotSupported = 501;
ecTextDriverError = 502;
ecTextModeNotFound = 503;
{ Compression errors }
ecInvalidCompressionSource = 601;
ecCompressionBitSizeError = 602;
ecCompressorNotSpecified = 603;
{ List Errors }
ecListCapacityOverflow = 701;
ecIndexOutOfBounds = 702;
{ Image errors }
ecImageBppNotSupported = 801;
ecInvalidImage = 802;
ecImageCompressionNotSupported = 803;
ecImageVersionNotSupported = 804;
ecImageTooLarge = 805;
{ Font Errors }
ecFontVersionNotSupported = 901;
ecFontCompressionNotSupported = 902;
{ File Errors }
ecPathNotFound = 1001;
ecFileAccessDenied = 1003;
ecFileInvalidHandle = 1004;
ecFileInvalidEnvironment = 1005;
ecFileInvalidFormat = 1006;
ecDirChangeError = 1007;
ecFileInvalidVersion = 1008;
{ System errors }
ecNullParameter = 1101;
ecInvalidOperation = 1102;
ecInvalidArgument = 1103;
{ User defined errors }
ecUser = 5000;
{ Status codes }
sOk = 0;
sHint = 1;
sWarning = 2;
sException = 3;
sFileStatus = 100;
sUserStatus = 1000;
function ErrorMessage(AErrorCode: word): string; far;
var
CustomErrorMessageProc: PCustomErrorMessageProc;
implementation
uses
AplObj,
AplStr,
AplUtils,
Strings,
Lists;
type
PError = ^TError;
PErrorList = ^TErrorList;
TError = object(TObject)
private
public
ErrorCode: integer;
ErrorMessage: PChar;
constructor Create(AErrorCode: word; AErrorMessage: string);
constructor CreateCode(AErrorCode: word);
destructor Free; virtual;
procedure Init; virtual;
function GetErrorMessage: string;
end;
TErrorList = object(TObjectList)
private
public
constructor Create;
procedure Init; virtual;
function Add(AItem: PError): integer;
function GetItem(AIndex: integer): PError;
function GetErrorByCode(AErrorCode: word): PError;
function IndexOf(AItem: PError): integer;
procedure SetItem(AIndex: integer; AItem: PError);
procedure Insert(AIndex: integer; AItem: PError);
procedure RemoveItem(AItem: PError);
procedure AddError(AErrorCode: word; AErrorMessage: string);
end;
var
ErrorList: PErrorList;
function ErrorMessage(AErrorCode: word): string;
var
error: PError;
found: boolean;
begin
error := ErrorList^.GetErrorByCode(AErrorCode);
if Assigned(error) then
ErrorMessage := error^.GetErrorMessage
else begin
if AErrorCode >= ecUser then begin
if Assigned(CustomErrorMessageProc) then begin
found := false;
ErrorMessage := TCustomErrorMessageProc(CustomErrorMessageProc)(AErrorCode, found);
if found then
exit;
end;
end;
ErrorMessage := 'Unknown error';
end;
end;
constructor TError.Create(AErrorCode: word; AErrorMessage: string);
begin
inherited Create;
ErrorCode := AErrorCode;
ErrorMessage := TString.New(AErrorMessage);
end;
constructor TError.CreateCode(AErrorCode: word);
begin
inherited Create;
ErrorCode := AErrorCode;
end;
destructor TError.Free;
begin
TString.Free(ErrorMessage);
inherited Free;
end;
procedure TError.Init;
begin
inherited Init;
ErrorCode := 0;
ErrorMessage := nil;
end;
function TError.GetErrorMessage: string;
begin
GetErrorMessage := TString.GetString(ErrorMessage);
end;
function ErrorCodeCompare(AItem1, AItem2: pointer): integer; far;
begin
ErrorCodeCompare := PError(AItem1)^.ErrorCode - PError(AItem2)^.ErrorCode;
end;
constructor TErrorList.Create;
var
index: integer;
item: PError;
begin
inherited CreateSorted(ErrorCodeCompare);
AddError(ecImageVersionNotSupported, 'Image version not supported');
AddError(ecFileNotFound, 'File not found');
AddError(ecFileCreateError, 'File could not be created');
AddError(ecFileOpenError, 'File could not be opened');
AddError(ecFileReadError, 'Error writing file');
AddError(ecFileWriteError, 'Error writing file');
AddError(ecFileVersionError, 'File version mismatch');
AddError(ecFileTypeError, 'File type not supported');
AddError(ecFileInvalid, 'File is invalid');
AddError(ecGraphicsNotSupported, 'Graphics type not supported');
AddError(ecTextDriverNotSupported, 'Text type not supported');
AddError(ecTextDriverError, 'Text driver error');
AddError(ecTextModeNotFound, 'Text mode not found');
AddError(ecMemoryReferenceNotFound, 'Memory reference not found');
AddError(ecInvalidMemoryReference, 'Invalid memory reference');
AddError(ecNotEnoughMemory, 'Not enough memory');
AddError(ecInvalidAllocSize, 'Invalid allocation size');
AddError(ecGraphicsDriverError, 'Graphics mode not supported');
AddError(ecStreamSeekNotSupported, 'Stream does not support seeking');
AddError(ecStreamWriteNotSupported, 'Stream does not support writing');
AddError(ecStreamReadNotSupported, 'Stream does not support reading');
AddError(ecSeekPastStreamEnd, 'Seek past end of stream');
AddError(ecWritePastStreamEnd, 'Write past end of stream');
AddError(ecReadPastStreamEnd, 'Read past end of stream');
AddError(ecStreamNotOpen, 'Stream is not open');
AddError(ecXmsNotInitialized, 'XMS memory could not be initialized');
AddError(ecXmsNotSupported, 'XMS memory is not supported');
AddError(ecStreamCloseError, 'Error closing stream');
AddError(ecStreamOpenError, 'Error opening stream');
AddError(ecStreamReadError, 'Error reading stream');
AddError(ecStreamWriteError, 'Error writing stream');
AddError(ecStreamSeekError, 'Stream seek error');
AddError(ecGraphicsModeNotFound, 'Graphics mode not found');
AddError(ecInvalidCompressionSource, 'Compression source is invalid');
AddError(ecImageBppNotSupported, 'Image bit depth not supported');
AddError(ecListCapacityOverflow, 'List capacity overflow');
AddError(ecInvalidImage, 'Invalid image data');
AddError(ecImageCompressionNotSupported, 'Image compression not supported');
AddError(ecStreamFormatNotSupported, 'Stream format not supported');
AddError(ecFontVersionNotSupported, 'Font version not supported');
AddError(ecPathNotFound, 'Path not found');
AddError(ecFileAccessDenied, 'File access denied');
AddError(ecFileInvalidHandle, 'Invalid file handle');
AddError(ecFileInvalidEnvironment, 'Invalid environment');
AddError(ecFileInvalidFormat, 'Invalid file format');
AddError(ecDirChangeError, 'Error changing directory');
AddError(ecIndexOutOfBounds, 'List index out of bounds');
AddError(ecFileInvalidVersion, 'Unsupported file version');
AddError(ecNullParameter, 'Null parameter');
AddError(ecInvalidOperation, 'Invalid operation');
AddError(ecInvalidArgument, 'Invalid argument');
AddError(ecUnsupportedPaletteFormat, 'Unsupported palette format');
AddError(ecInvalidPalette, 'Invalid palette');
AddError(ecCompressionBitSizeError, 'Compression bit size too large');
AddError(ecCompressorNotSpecified, 'Compressor not specified');
AddError(ecImageTooLarge, 'Image too large');
end;
procedure TErrorList.AddError(AErrorCode: word; AErrorMessage: string);
begin
Add(New(PError, Create(AErrorCode, AErrorMessage)));
end;
procedure TErrorList.Init;
var
error: PError;
begin
inherited Init;
end;
function TErrorList.Add(AItem: PError): integer;
begin
inherited Add(AItem);
end;
function TErrorList.GetItem(AIndex: integer): PError;
begin
GetItem := PError(inherited GetItem(AIndex));
end;
function TErrorList.IndexOf(AItem: PError): integer;
begin
IndexOf := inherited IndexOf(AItem);
end;
procedure TErrorList.SetItem(AIndex: integer; AItem: PError);
begin
inherited SetItem(AIndex, AItem);
end;
procedure TErrorList.Insert(AIndex: integer; AItem: PError);
begin
inherited Insert(AIndex, AItem);
end;
procedure TErrorList.RemoveItem(AItem: PError);
begin
inherited RemoveItem(AItem);
end;
function TErrorList.GetErrorByCode(AErrorCode: word): PError;
var
index: integer;
searchValue: TError;
begin
GetErrorByCode := nil;
searchValue.CreateCode(AErrorCode);
index := BinarySearch(@searchValue);
searchValue.Free;
if index >= 0 then
GetErrorByCode := GetItem(index);
end;
var
PreviousExitProc: PProc;
procedure Finalize; far;
begin
ExitProc := PreviousExitProc;
FreeAndNil(ErrorList);
end;
begin
PreviousExitProc := ExitProc;
ExitProc := @Finalize;
CustomErrorMessageProc := nil;
ErrorList := New(PErrorList, Create);
end.