| 1 | Unit ACLUtility;
|
|---|
| 2 |
|
|---|
| 3 | Interface
|
|---|
| 4 |
|
|---|
| 5 | Uses
|
|---|
| 6 | Classes, SysUtils,
|
|---|
| 7 | {$ifdef os2}
|
|---|
| 8 | Os2Def, IniFiles;
|
|---|
| 9 | {$endif}
|
|---|
| 10 | {$ifdef win32}
|
|---|
| 11 | Registry;
|
|---|
| 12 | {$endif}
|
|---|
| 13 |
|
|---|
| 14 | function GetACLLibraryVersion: string;
|
|---|
| 15 |
|
|---|
| 16 | Type
|
|---|
| 17 | TPrintOutput = procedure( TheText: string ) of object;
|
|---|
| 18 | TTerminateCheck = function: boolean of object;
|
|---|
| 19 | TProgressCallback = procedure( n, outof: integer;
|
|---|
| 20 | Message: string ) of object;
|
|---|
| 21 |
|
|---|
| 22 | const
|
|---|
| 23 | _MAX_PATH = 260; // max. length of full pathname
|
|---|
| 24 | _MAX_DRIVE = 3; // max. length of drive component
|
|---|
| 25 | _MAX_DIR = 256; // max. length of path component
|
|---|
| 26 | _MAX_FNAME = 256; // max. length of file name component
|
|---|
| 27 | _MAX_EXT = 256; // max. length of extension component
|
|---|
| 28 |
|
|---|
| 29 | mrFailed = $c000 + 1;
|
|---|
| 30 |
|
|---|
| 31 | {$ifdef win32}
|
|---|
| 32 | Function GetAPIErrorString( ErrorCode: integer ): string;
|
|---|
| 33 | Function GetLastAPIErrorString: string;
|
|---|
| 34 | {$endif}
|
|---|
| 35 |
|
|---|
| 36 | Type
|
|---|
| 37 | TMyIniFile =
|
|---|
| 38 | {$ifdef os2}
|
|---|
| 39 | class( TAsciiIniFile )
|
|---|
| 40 | {$else}
|
|---|
| 41 | class( TRegIniFile )
|
|---|
| 42 | {$endif}
|
|---|
| 43 | constructor CreateMe( const Path: string );
|
|---|
| 44 | destructor Destroy; override;
|
|---|
| 45 | end;
|
|---|
| 46 |
|
|---|
| 47 | {$ifdef os2}
|
|---|
| 48 | function AllocateMemory( const Size: longint ): pointer;
|
|---|
| 49 | procedure DeallocateMemory( Var P: pointer );
|
|---|
| 50 | procedure Sleep( const milliseconds: longint );
|
|---|
| 51 | {$endif}
|
|---|
| 52 |
|
|---|
| 53 | // allocate a new copy of the given source memory
|
|---|
| 54 | procedure AllocMemCopy( const Source: pointer;
|
|---|
| 55 | var Dest: pointer;
|
|---|
| 56 | const Size: longint );
|
|---|
| 57 |
|
|---|
| 58 | procedure MemCopy( const Source: pointer;
|
|---|
| 59 | const Dest: pointer;
|
|---|
| 60 | const Size: longint );
|
|---|
| 61 |
|
|---|
| 62 | procedure FillMem( Dest: pointer;
|
|---|
| 63 | Size: longint;
|
|---|
| 64 | Data: Byte );
|
|---|
| 65 |
|
|---|
| 66 | // Returns A - B
|
|---|
| 67 | function PtrDiff( A, B: pointer ): longword;
|
|---|
| 68 |
|
|---|
| 69 | function Min( const a: longint;
|
|---|
| 70 | const b: longint ): longint;
|
|---|
| 71 |
|
|---|
| 72 | function Max( const a: longint;
|
|---|
| 73 | const b: longint ): longint;
|
|---|
| 74 |
|
|---|
| 75 | function Between( const Value: longint;
|
|---|
| 76 | const Limit1: longint;
|
|---|
| 77 | const Limit2: longint ): boolean;
|
|---|
| 78 |
|
|---|
| 79 | function PtrBetween( const Value: pointer;
|
|---|
| 80 | const Limit1: pointer;
|
|---|
| 81 | const Limit2: pointer ): boolean;
|
|---|
| 82 |
|
|---|
| 83 | Procedure AddList( Source, Dest: TList );
|
|---|
| 84 |
|
|---|
| 85 | Procedure AssignList( Source, Dest: TList );
|
|---|
| 86 |
|
|---|
| 87 | // Destroy the objects stored in List
|
|---|
| 88 | // and clear the list.
|
|---|
| 89 | Procedure ClearListAndObjects( List: TList );
|
|---|
| 90 |
|
|---|
| 91 | // Destroy the objects stored in the list
|
|---|
| 92 | // and then destroy the list itself
|
|---|
| 93 | // And set the reference to nil
|
|---|
| 94 | Procedure DestroyListAndObjects( Var List: TList );
|
|---|
| 95 |
|
|---|
| 96 | // Destroy the objects stored in the list.
|
|---|
| 97 | // You probably want to use one of the two functions above.
|
|---|
| 98 | Procedure DestroyListObjects( List: TList );
|
|---|
| 99 |
|
|---|
| 100 | // Returns the filename of the running app
|
|---|
| 101 | // (including drive/directory)
|
|---|
| 102 | Function GetApplicationFilename: string;
|
|---|
| 103 |
|
|---|
| 104 | // Returns the starting directory of the app
|
|---|
| 105 | Function GetApplicationDir: string;
|
|---|
| 106 |
|
|---|
| 107 | {$ifdef win32}
|
|---|
| 108 | type
|
|---|
| 109 | TDaylightSavingStatus =
|
|---|
| 110 | (
|
|---|
| 111 | dssDisabled,
|
|---|
| 112 | dssDaylightSaving,
|
|---|
| 113 | dssNormal
|
|---|
| 114 | );
|
|---|
| 115 |
|
|---|
| 116 | function GetDaylightSavingStatus: TDaylightSavingStatus;
|
|---|
| 117 | {$endif}
|
|---|
| 118 |
|
|---|
| 119 | type
|
|---|
| 120 | TDataList = TList; // to help distinguish from TObjectList below
|
|---|
| 121 |
|
|---|
| 122 | type
|
|---|
| 123 | TObjectListSortCompare = function ( Item1, Item2: TObject ): Integer;
|
|---|
| 124 |
|
|---|
| 125 | // TObjectList has exactly the same functionality as TList,
|
|---|
| 126 | // except that rather than using untyped pointers it expects
|
|---|
| 127 | // object references. This means that incorrect typecasts can
|
|---|
| 128 | // be detected when using the list
|
|---|
| 129 | TObjectList = class( TList )
|
|---|
| 130 | protected
|
|---|
| 131 | function Get( index: integer ): TObject;
|
|---|
| 132 | procedure Put( index: integer; Item: TObject );
|
|---|
| 133 | public
|
|---|
| 134 | function Add( item: TObject ): integer;
|
|---|
| 135 | function First: TObject;
|
|---|
| 136 | function IndexOf( item: TObject ): integer;
|
|---|
| 137 | procedure Insert( Index: Integer; Item: TObject );
|
|---|
| 138 | function Last: TObject;
|
|---|
| 139 | function Remove( Item: TObject ): Integer;
|
|---|
| 140 | procedure Sort( Compare: TObjectListSortCompare );
|
|---|
| 141 | property Items[ index: integer ]: TObject read Get write Put; default;
|
|---|
| 142 |
|
|---|
| 143 | // Additional:
|
|---|
| 144 | // Copy the given list to this one.
|
|---|
| 145 | procedure Assign( Source: TObjectList );
|
|---|
| 146 | // Add the objects in the given list to this one
|
|---|
| 147 | procedure AddList( Source: TObjectList );
|
|---|
| 148 |
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | // Raise an exception if the given Code is <> 0
|
|---|
| 152 | procedure CheckSystemError( Code: longword;
|
|---|
| 153 | Message: string );
|
|---|
| 154 |
|
|---|
| 155 | {$ifdef os2}
|
|---|
| 156 | function GetUserProfileString( const AppName: string;
|
|---|
| 157 | const KeyName: string;
|
|---|
| 158 | const Default: string ): string;
|
|---|
| 159 |
|
|---|
| 160 | Procedure SetUserProfileString( const AppName: string;
|
|---|
| 161 | const KeyName: string;
|
|---|
| 162 | const Value: string );
|
|---|
| 163 |
|
|---|
| 164 | Procedure LoadDLLFunction( const DLLName: string;
|
|---|
| 165 | const FunctionName: string;
|
|---|
| 166 | var hDLL: HMODULE;
|
|---|
| 167 | var F: pointer );
|
|---|
| 168 |
|
|---|
| 169 | {$endif}
|
|---|
| 170 |
|
|---|
| 171 | Implementation
|
|---|
| 172 |
|
|---|
| 173 | // Implementation ------------------------------------------
|
|---|
| 174 |
|
|---|
| 175 | Uses
|
|---|
| 176 | {$ifdef os2}
|
|---|
| 177 | Dos, BseDos, BseTib, PmWin, PmGpi, PmDev, PmShl;
|
|---|
| 178 | {$else}
|
|---|
| 179 | Windows, FileCtrl;
|
|---|
| 180 | {$endif}
|
|---|
| 181 |
|
|---|
| 182 | constructor TMyIniFile.CreateMe( const Path: string );
|
|---|
| 183 | begin
|
|---|
| 184 | {$ifdef os2}
|
|---|
| 185 | Inherited Create( Path );
|
|---|
| 186 | {$else}
|
|---|
| 187 | Inherited Create( Path );
|
|---|
| 188 | {$endif}
|
|---|
| 189 | end;
|
|---|
| 190 |
|
|---|
| 191 | destructor TMyIniFile.Destroy;
|
|---|
| 192 | begin
|
|---|
| 193 | {$ifdef os2}
|
|---|
| 194 | Refresh;
|
|---|
| 195 | {$endif}
|
|---|
| 196 | inherited Destroy;
|
|---|
| 197 | end;
|
|---|
| 198 |
|
|---|
| 199 | {$ifdef os2}
|
|---|
| 200 | function AllocateMemory( const Size: longint ): pointer;
|
|---|
| 201 | begin
|
|---|
| 202 | GetMem( Result, size + sizeof( Size ) );
|
|---|
| 203 | pLong( Result )^ := Size;
|
|---|
| 204 | inc( Result, sizeof( Size ) );
|
|---|
| 205 | end;
|
|---|
| 206 |
|
|---|
| 207 | procedure DeallocateMemory( Var P: pointer );
|
|---|
| 208 | var
|
|---|
| 209 | Size: longint;
|
|---|
| 210 | begin
|
|---|
| 211 | if P = nil then
|
|---|
| 212 | exit;
|
|---|
| 213 |
|
|---|
| 214 | dec( P, sizeof( Size ) );
|
|---|
| 215 | Size := pLong( P )^;
|
|---|
| 216 | FreeMem( P, Size + sizeof( Size ) );
|
|---|
| 217 | P := nil;
|
|---|
| 218 | end;
|
|---|
| 219 | {$endif}
|
|---|
| 220 |
|
|---|
| 221 | {$ifdef win32}
|
|---|
| 222 | Function GetAPIErrorString( ErrorCode: integer ): string;
|
|---|
| 223 | var
|
|---|
| 224 | buffer: array[ 0..1000 ] of char;
|
|---|
| 225 | begin
|
|---|
| 226 | if FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,
|
|---|
| 227 | nil, // no special message source
|
|---|
| 228 | ErrorCode,
|
|---|
| 229 | 0, // use default language
|
|---|
| 230 | Buffer,
|
|---|
| 231 | Sizeof( Buffer ),
|
|---|
| 232 | nil ) > 0
|
|---|
| 233 | then // no arguments
|
|---|
| 234 | Result:= IntToStr( ErrorCode ) + ': ' + Buffer
|
|---|
| 235 | else
|
|---|
| 236 | Result:= '(Unknown error)';
|
|---|
| 237 |
|
|---|
| 238 | end;
|
|---|
| 239 |
|
|---|
| 240 | Function GetLastAPIErrorString: string;
|
|---|
| 241 | begin
|
|---|
| 242 | Result := GetAPIErrorString( GetLastError );
|
|---|
| 243 | end;
|
|---|
| 244 | {$endif}
|
|---|
| 245 |
|
|---|
| 246 | procedure AllocMemCopy( const Source: pointer;
|
|---|
| 247 | var Dest: pointer;
|
|---|
| 248 | const Size: longint );
|
|---|
| 249 | begin
|
|---|
| 250 | GetMem( Dest, Size );
|
|---|
| 251 | MemCopy( Source, Dest, Size );
|
|---|
| 252 | end;
|
|---|
| 253 |
|
|---|
| 254 | procedure MemCopy( const Source: pointer;
|
|---|
| 255 | const Dest: pointer;
|
|---|
| 256 | const Size: longint );
|
|---|
| 257 | begin
|
|---|
| 258 | Move( Source^, Dest^, Size );
|
|---|
| 259 | end;
|
|---|
| 260 |
|
|---|
| 261 | procedure FillMem( Dest: pointer;
|
|---|
| 262 | Size: longint;
|
|---|
| 263 | Data: Byte );
|
|---|
| 264 | begin
|
|---|
| 265 | FillChar( Dest^, Size, Data );
|
|---|
| 266 | end;
|
|---|
| 267 |
|
|---|
| 268 | function PtrDiff( A, B: pointer ): longword;
|
|---|
| 269 | begin
|
|---|
| 270 | result:= longword( A ) - longword( B );
|
|---|
| 271 | end;
|
|---|
| 272 |
|
|---|
| 273 | Procedure AddList( Source, Dest: TList );
|
|---|
| 274 | var
|
|---|
| 275 | i: longint;
|
|---|
| 276 | begin
|
|---|
| 277 | // expand the destination list
|
|---|
| 278 | // to what's required
|
|---|
| 279 | Dest.Capacity := Dest.Capacity
|
|---|
| 280 | + Source.Capacity;
|
|---|
| 281 | for i:= 0 to Source.Count - 1 do
|
|---|
| 282 | Dest.Add( Source[ i ] );
|
|---|
| 283 | end;
|
|---|
| 284 |
|
|---|
| 285 | Procedure AssignList( Source, Dest: TList );
|
|---|
| 286 | begin
|
|---|
| 287 | Dest.Clear;
|
|---|
| 288 | AddList( Source, Dest );
|
|---|
| 289 | end;
|
|---|
| 290 |
|
|---|
| 291 | {$ifdef win32}
|
|---|
| 292 | function GetDaylightSavingStatus: TDaylightSavingStatus;
|
|---|
| 293 | var
|
|---|
| 294 | TimeZoneInfo: TIME_ZONE_INFORMATION;
|
|---|
| 295 | ZoneID: DWORD;
|
|---|
| 296 | Begin
|
|---|
| 297 | ZoneID:= GetTimeZoneInformation( TimeZoneInfo );
|
|---|
| 298 | if TimeZoneInfo.DaylightBias = 0 then
|
|---|
| 299 | Result:= dssDisabled
|
|---|
| 300 | else if ZoneID = TIME_ZONE_ID_DAYLIGHT then
|
|---|
| 301 | Result:= dssDaylightSaving
|
|---|
| 302 | else
|
|---|
| 303 | Result:= dssNormal;
|
|---|
| 304 | end;
|
|---|
| 305 | {$endif}
|
|---|
| 306 |
|
|---|
| 307 | // Destroy the objects stored in List
|
|---|
| 308 | // and clear the list.
|
|---|
| 309 | Procedure ClearListAndObjects( List: TList );
|
|---|
| 310 | begin
|
|---|
| 311 | DestroyListObjects( List );
|
|---|
| 312 | List.Clear;
|
|---|
| 313 | end;
|
|---|
| 314 |
|
|---|
| 315 | // Destroy the objects stored in the list
|
|---|
| 316 | // and then destroy the list itself.
|
|---|
| 317 | Procedure DestroyListAndObjects( Var List: TList );
|
|---|
| 318 | begin
|
|---|
| 319 | if not Assigned( List ) then
|
|---|
| 320 | exit;
|
|---|
| 321 |
|
|---|
| 322 | DestroyListObjects( List );
|
|---|
| 323 | List.Destroy;
|
|---|
| 324 | List := nil;
|
|---|
| 325 | end;
|
|---|
| 326 |
|
|---|
| 327 | Procedure DestroyListObjects( List: TList );
|
|---|
| 328 | var
|
|---|
| 329 | Index: longint;
|
|---|
| 330 | begin
|
|---|
| 331 | for Index := 0 to List.Count - 1 do
|
|---|
| 332 | begin
|
|---|
| 333 | if List[ Index ] <> nil then
|
|---|
| 334 | begin
|
|---|
| 335 | TObject( List[ Index ] ).Destroy;
|
|---|
| 336 | List[ Index ] := nil;
|
|---|
| 337 | end;
|
|---|
| 338 | end;
|
|---|
| 339 | end;
|
|---|
| 340 |
|
|---|
| 341 | function Min( const a: longint;
|
|---|
| 342 | const b: longint ): longint;
|
|---|
| 343 | begin
|
|---|
| 344 | if a<b then
|
|---|
| 345 | result:= a
|
|---|
| 346 | else
|
|---|
| 347 | result:= b;
|
|---|
| 348 | end;
|
|---|
| 349 |
|
|---|
| 350 | function Max( const a: longint;
|
|---|
| 351 | const b: longint ): longint;
|
|---|
| 352 | begin
|
|---|
| 353 | if a>b then
|
|---|
| 354 | result:= a
|
|---|
| 355 | else
|
|---|
| 356 | result:= b;
|
|---|
| 357 | end;
|
|---|
| 358 |
|
|---|
| 359 | function Between( const Value: longint;
|
|---|
| 360 | const Limit1: longint;
|
|---|
| 361 | const Limit2: longint ): boolean;
|
|---|
| 362 | begin
|
|---|
| 363 | if Limit1 < Limit2 then
|
|---|
| 364 | Result:= ( Value >= Limit1 ) and ( Value <= Limit2 )
|
|---|
| 365 | else
|
|---|
| 366 | Result:= ( Value >= Limit2 ) and ( Value <= Limit1 )
|
|---|
| 367 | end;
|
|---|
| 368 |
|
|---|
| 369 | function PtrBetween( const Value: pointer;
|
|---|
| 370 | const Limit1: pointer;
|
|---|
| 371 | const Limit2: pointer ): boolean;
|
|---|
| 372 | var
|
|---|
| 373 | v, p1, p2: pchar;
|
|---|
| 374 | begin
|
|---|
| 375 | v := Value;
|
|---|
| 376 | p1 := Limit1;
|
|---|
| 377 | p2 := Limit2;
|
|---|
| 378 | if p1 < p2 then
|
|---|
| 379 | Result:= ( V >= p1 ) and ( V <= p2 )
|
|---|
| 380 | else
|
|---|
| 381 | Result:= ( V >= p2 ) and ( V <= p1 )
|
|---|
| 382 | end;
|
|---|
| 383 |
|
|---|
| 384 | {$ifdef os2}
|
|---|
| 385 | Function GetApplicationFilename: string;
|
|---|
| 386 | var
|
|---|
| 387 | pThreadInfo: PTIB;
|
|---|
| 388 | pProcessInfo: PPIB;
|
|---|
| 389 | ProcessName: cstring[ _MAX_PATH ];
|
|---|
| 390 | begin
|
|---|
| 391 | DosGetInfoBlocks( pThreadInfo,
|
|---|
| 392 | pProcessInfo );
|
|---|
| 393 | DosQueryModuleName( pProcessInfo^.pib_hmte,
|
|---|
| 394 | sizeof( ProcessName ),
|
|---|
| 395 | ProcessName );
|
|---|
| 396 | Result := ProcessName;
|
|---|
| 397 | end;
|
|---|
| 398 | {$else}
|
|---|
| 399 | Function GetApplicationFilename: string;
|
|---|
| 400 | var
|
|---|
| 401 | ProcessName: array[ 0.._MAX_PATH ] of char;
|
|---|
| 402 | begin
|
|---|
| 403 | GetModuleFileName( 0, // our own process
|
|---|
| 404 | ProcessName,
|
|---|
| 405 | sizeof( ProcessName ) );
|
|---|
| 406 |
|
|---|
| 407 | Result := ProcessName;
|
|---|
| 408 | end;
|
|---|
| 409 | {$endif}
|
|---|
| 410 |
|
|---|
| 411 | Function GetApplicationDir: string;
|
|---|
| 412 | begin
|
|---|
| 413 | Result := ExtractFilePath( GetApplicationFilename );
|
|---|
| 414 | end;
|
|---|
| 415 |
|
|---|
| 416 | { TObjectList }
|
|---|
| 417 |
|
|---|
| 418 | function TObjectList.Add( item: TObject ): integer;
|
|---|
| 419 | begin
|
|---|
| 420 | result := inherited Add( item );
|
|---|
| 421 | end;
|
|---|
| 422 |
|
|---|
| 423 | function TObjectList.First: TObject;
|
|---|
| 424 | begin
|
|---|
| 425 | result := inherited First;
|
|---|
| 426 | end;
|
|---|
| 427 |
|
|---|
| 428 | function TObjectList.Get( index: integer ): TObject;
|
|---|
| 429 | begin
|
|---|
| 430 | result := Items[ Index ];
|
|---|
| 431 | end;
|
|---|
| 432 |
|
|---|
| 433 | function TObjectList.IndexOf( item: TObject ): integer;
|
|---|
| 434 | begin
|
|---|
| 435 | result := inherited IndexOf( item );
|
|---|
| 436 | end;
|
|---|
| 437 |
|
|---|
| 438 | procedure TObjectList.Insert( Index: Integer; Item: TObject );
|
|---|
| 439 | begin
|
|---|
| 440 | inherited Insert( Index, Item );
|
|---|
| 441 | end;
|
|---|
| 442 |
|
|---|
| 443 | function TObjectList.Last: TObject;
|
|---|
| 444 | begin
|
|---|
| 445 | result := inherited Last;
|
|---|
| 446 | end;
|
|---|
| 447 |
|
|---|
| 448 | procedure TObjectList.Put( index: integer; Item: TObject );
|
|---|
| 449 | begin
|
|---|
| 450 | Items[ Index ] := Item;
|
|---|
| 451 | end;
|
|---|
| 452 |
|
|---|
| 453 | function TObjectList.Remove( Item: TObject ): Integer;
|
|---|
| 454 | begin
|
|---|
| 455 | result := inherited Remove( Item );
|
|---|
| 456 | end;
|
|---|
| 457 |
|
|---|
| 458 | procedure QuickSortObjectList( SortList: PPointerList;
|
|---|
| 459 | L, R: Integer;
|
|---|
| 460 | CompareFunction: TObjectListSortCompare );
|
|---|
| 461 | var
|
|---|
| 462 | I, J: Integer;
|
|---|
| 463 | P, T: Pointer;
|
|---|
| 464 | begin
|
|---|
| 465 | repeat
|
|---|
| 466 | I := L;
|
|---|
| 467 | J := R;
|
|---|
| 468 | P := SortList^[(L + R) shr 1];
|
|---|
| 469 | repeat
|
|---|
| 470 | while CompareFunction( TObject( SortList^[I] ), P ) < 0 do
|
|---|
| 471 | Inc(I);
|
|---|
| 472 | while CompareFunction( TObject( SortList^[J] ), P) > 0 do
|
|---|
| 473 | Dec(J);
|
|---|
| 474 | if I <= J then
|
|---|
| 475 | begin
|
|---|
| 476 | T := SortList^[I];
|
|---|
| 477 | SortList^[I] := SortList^[J];
|
|---|
| 478 | SortList^[J] := T;
|
|---|
| 479 | Inc(I);
|
|---|
| 480 | Dec(J);
|
|---|
| 481 | end;
|
|---|
| 482 | until I > J;
|
|---|
| 483 | if L < J then
|
|---|
| 484 | QuickSortObjectList( SortList, L, J, CompareFunction );
|
|---|
| 485 | L := I;
|
|---|
| 486 | until I >= R;
|
|---|
| 487 | end;
|
|---|
| 488 |
|
|---|
| 489 | procedure TObjectList.Sort( Compare: TObjectListSortCompare );
|
|---|
| 490 | begin
|
|---|
| 491 | if ( List <> nil ) and ( Count > 0 ) then
|
|---|
| 492 | QuickSortObjectList( List, 0, Count - 1, Compare );
|
|---|
| 493 | end;
|
|---|
| 494 |
|
|---|
| 495 | procedure TObjectList.Assign( Source: TObjectList );
|
|---|
| 496 | begin
|
|---|
| 497 | Clear;
|
|---|
| 498 | AddList( Source );
|
|---|
| 499 | end;
|
|---|
| 500 |
|
|---|
| 501 | procedure TObjectList.AddList( Source: TObjectList );
|
|---|
| 502 | var
|
|---|
| 503 | i: integer;
|
|---|
| 504 | begin
|
|---|
| 505 | for i := 0 to Source.Count - 1 do
|
|---|
| 506 | Add( Source[ i ] );
|
|---|
| 507 | end;
|
|---|
| 508 |
|
|---|
| 509 | {$ifdef os2}
|
|---|
| 510 | procedure Sleep( const milliseconds: longint );
|
|---|
| 511 | begin
|
|---|
| 512 | DosSleep( milliseconds );
|
|---|
| 513 | end;
|
|---|
| 514 | {$endif}
|
|---|
| 515 |
|
|---|
| 516 | // Raise an exception if the given Code is <> 0
|
|---|
| 517 | procedure CheckSystemError( Code: longword;
|
|---|
| 518 | Message: string );
|
|---|
| 519 | begin
|
|---|
| 520 | if Code <> 0 then
|
|---|
| 521 | raise Exception.Create( Message
|
|---|
| 522 | + ': ['
|
|---|
| 523 | + IntToStr( Code )
|
|---|
| 524 | + '] '
|
|---|
| 525 | + SysErrorMessage( Code ) );
|
|---|
| 526 | end;
|
|---|
| 527 |
|
|---|
| 528 | {$ifdef os2}
|
|---|
| 529 | function GetUserProfileString( const AppName: string;
|
|---|
| 530 | const KeyName: string;
|
|---|
| 531 | const Default: string ): string;
|
|---|
| 532 | var
|
|---|
| 533 | Buffer: array[ 0..255 ] of char;
|
|---|
| 534 | Len: longint;
|
|---|
| 535 | i: longint;
|
|---|
| 536 | szDefault: cstring;
|
|---|
| 537 | begin
|
|---|
| 538 | szDefault := Default;
|
|---|
| 539 | Len := PrfQueryProfileString( HINI_USERPROFILE, // user profile
|
|---|
| 540 | AppName, // application
|
|---|
| 541 | KeyName, // key
|
|---|
| 542 | szDefault,
|
|---|
| 543 | Buffer,
|
|---|
| 544 | sizeof( Buffer ) );
|
|---|
| 545 |
|
|---|
| 546 | // remove null terminator, if present
|
|---|
| 547 | if Len > 0 then
|
|---|
| 548 | if Buffer[ Len - 1 ] = #0 then
|
|---|
| 549 | dec( Len );
|
|---|
| 550 | Result := '';
|
|---|
| 551 | for i := 0 to Len - 1 do
|
|---|
| 552 | Result := Result + Buffer[ i ];
|
|---|
| 553 | end;
|
|---|
| 554 |
|
|---|
| 555 | Procedure SetUserProfileString( const AppName: string;
|
|---|
| 556 | const KeyName: string;
|
|---|
| 557 | const Value: string );
|
|---|
| 558 | begin
|
|---|
| 559 | if not PrfWriteProfileString( HINI_USERPROFILE, // user profile
|
|---|
| 560 | AppName, // application
|
|---|
| 561 | KeyName, // key
|
|---|
| 562 | Value ) then
|
|---|
| 563 | raise Exception.Create(
|
|---|
| 564 | 'Error writing INI ['
|
|---|
| 565 | + AppName
|
|---|
| 566 | + '/'
|
|---|
| 567 | + KeyName
|
|---|
| 568 | + '] rc = '
|
|---|
| 569 | + IntToHex( WinGetLastError( AppHandle ), 8 ) );
|
|---|
| 570 | end;
|
|---|
| 571 |
|
|---|
| 572 | procedure LoadDLLFunction( const DLLName: string;
|
|---|
| 573 | const FunctionName: string;
|
|---|
| 574 | var hDLL: HMODULE;
|
|---|
| 575 | var F: pointer );
|
|---|
| 576 | var
|
|---|
| 577 | ActualDLLName: string;
|
|---|
| 578 | csErrorObject: cstring;
|
|---|
| 579 | csFunctionName: cstring;
|
|---|
| 580 | rc: APIRET;
|
|---|
| 581 | begin
|
|---|
| 582 | F := nil;
|
|---|
| 583 |
|
|---|
| 584 | if hDLL = NullHandle then
|
|---|
| 585 | begin
|
|---|
| 586 | ActualDLLName := GetApplicationDir + DLLName;
|
|---|
| 587 | if not FileExists( ActualDLLName ) then
|
|---|
| 588 | ActualDLLName := DLLName;
|
|---|
| 589 |
|
|---|
| 590 | rc := DosLoadModule( csErrorObject,
|
|---|
| 591 | sizeof( csErrorObject ),
|
|---|
| 592 | ActualDLLName,
|
|---|
| 593 | hDLL );
|
|---|
| 594 | if rc <> 0 then
|
|---|
| 595 | raise Exception.Create( DLLName
|
|---|
| 596 | + ' could not be loaded: '
|
|---|
| 597 | + SysErrorMessage( rc ) );
|
|---|
| 598 |
|
|---|
| 599 | end;
|
|---|
| 600 |
|
|---|
| 601 | csFunctionName := FunctionName;
|
|---|
| 602 | rc := DosQueryProcAddr( hDLL,
|
|---|
| 603 | 0, // using by name
|
|---|
| 604 | csFunctionName,
|
|---|
| 605 | F );
|
|---|
| 606 | if rc <> 0 then
|
|---|
| 607 | raise Exception.Create( FunctionName
|
|---|
| 608 | + ' in '
|
|---|
| 609 | + DLLName
|
|---|
| 610 | + ': '
|
|---|
| 611 | + SysErrorMessage( rc ) );
|
|---|
| 612 | end;
|
|---|
| 613 |
|
|---|
| 614 | {$endif}
|
|---|
| 615 |
|
|---|
| 616 | const
|
|---|
| 617 | LibVersion = 'V1.5.14'; // $SS_REQUIRE_NEW_VERSION$
|
|---|
| 618 |
|
|---|
| 619 | function GetACLLibraryVersion: string;
|
|---|
| 620 | begin
|
|---|
| 621 | Result := LibVersion;
|
|---|
| 622 | end;
|
|---|
| 623 |
|
|---|
| 624 | Initialization
|
|---|
| 625 | End.
|
|---|
| 626 |
|
|---|