Changeset 25 for trunk/Packages/Common
- Timestamp:
- Sep 10, 2022, 6:54:43 PM (2 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 32 added
- 8 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Common.lpk
r15 r25 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <CONFIG> 3 <Package Version=" 4">3 <Package Version="5"> 4 4 <PathDelim Value="\"/> 5 5 <Name Value="Common"/> … … 33 33 <Other> 34 34 <CompilerMessages> 35 <IgnoredMessages idx 5024="True"/>35 <IgnoredMessages idx6058="True" idx5071="True" idx5024="True" idx3124="True" idx3123="True"/> 36 36 </CompilerMessages> 37 37 </Other> 38 38 </CompilerOptions> 39 <Description Value="Various libraries"/> 40 <License Value="GNU/GPL"/> 41 <Version Minor="7"/> 42 <Files Count="21"> 39 <Description Value="Common package with various useful units. 40 41 Source: https://svn.zdechov.net/PascalClassLibrary/Common/"/> 42 <License Value="Copy left."/> 43 <Version Minor="10"/> 44 <Files Count="32"> 43 45 <Item1> 44 46 <Filename Value="StopWatch.pas"/> … … 60 62 <Item5> 61 63 <Filename Value="UPrefixMultiplier.pas"/> 64 <HasRegisterProc Value="True"/> 62 65 <UnitName Value="UPrefixMultiplier"/> 63 66 </Item5> … … 134 137 <UnitName Value="UTheme"/> 135 138 </Item21> 139 <Item22> 140 <Filename Value="UStringTable.pas"/> 141 <UnitName Value="UStringTable"/> 142 </Item22> 143 <Item23> 144 <Filename Value="UMetaCanvas.pas"/> 145 <UnitName Value="UMetaCanvas"/> 146 </Item23> 147 <Item24> 148 <Filename Value="UGeometric.pas"/> 149 <UnitName Value="UGeometric"/> 150 </Item24> 151 <Item25> 152 <Filename Value="UTranslator.pas"/> 153 <HasRegisterProc Value="True"/> 154 <UnitName Value="UTranslator"/> 155 </Item25> 156 <Item26> 157 <Filename Value="ULanguages.pas"/> 158 <UnitName Value="ULanguages"/> 159 </Item26> 160 <Item27> 161 <Filename Value="UFormAbout.pas"/> 162 <UnitName Value="UFormAbout"/> 163 </Item27> 164 <Item28> 165 <Filename Value="UAboutDialog.pas"/> 166 <HasRegisterProc Value="True"/> 167 <UnitName Value="UAboutDialog"/> 168 </Item28> 169 <Item29> 170 <Filename Value="UPixelPointer.pas"/> 171 <UnitName Value="UPixelPointer"/> 172 </Item29> 173 <Item30> 174 <Filename Value="UDataFile.pas"/> 175 <UnitName Value="UDataFile"/> 176 </Item30> 177 <Item31> 178 <Filename Value="UTestCase.pas"/> 179 <UnitName Value="UTestCase"/> 180 </Item31> 181 <Item32> 182 <Filename Value="UGenerics.pas"/> 183 <UnitName Value="UGenerics"/> 184 </Item32> 136 185 </Files> 186 <CompatibilityMode Value="True"/> 137 187 <i18n> 138 188 <EnableI18N Value="True"/> … … 140 190 <EnableI18NForLFM Value="True"/> 141 191 </i18n> 142 <RequiredPkgs Count=" 3">192 <RequiredPkgs Count="2"> 143 193 <Item1> 144 194 <PackageName Value="LCL"/> 145 195 </Item1> 146 196 <Item2> 147 <PackageName Value="TemplateGenerics"/>148 </Item2>149 <Item3>150 197 <PackageName Value="FCL"/> 151 198 <MinVersion Major="1" Valid="True"/> 152 </Item 3>199 </Item2> 153 200 </RequiredPkgs> 154 201 <UsageOptions> -
trunk/Packages/Common/Common.pas
r15 r25 5 5 unit Common; 6 6 7 {$warn 5023 off : no warning about unused units} 7 8 interface 8 9 9 10 uses 10 StopWatch, UCommon, UDebugLog, UDelay, UPrefixMultiplier, UURI, UThreading, 11 UMemory, UResetableThread, UPool, ULastOpenedList, URegistry, 12 UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort, 13 UPersistentForm, UFindFile, UScaleDPI, UTheme, LazarusPackageIntf; 11 StopWatch, UCommon, UDebugLog, UDelay, UPrefixMultiplier, UURI, UThreading, 12 UMemory, UResetableThread, UPool, ULastOpenedList, URegistry, 13 UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort, 14 UPersistentForm, UFindFile, UScaleDPI, UTheme, UStringTable, UMetaCanvas, 15 UGeometric, UTranslator, ULanguages, UFormAbout, UAboutDialog, 16 UPixelPointer, UDataFile, UTestCase, UGenerics, LazarusPackageIntf; 14 17 15 18 implementation … … 18 21 begin 19 22 RegisterUnit('UDebugLog', @UDebugLog.Register); 23 RegisterUnit('UPrefixMultiplier', @UPrefixMultiplier.Register); 20 24 RegisterUnit('ULastOpenedList', @ULastOpenedList.Register); 21 25 RegisterUnit('UJobProgressView', @UJobProgressView.Register); … … 26 30 RegisterUnit('UScaleDPI', @UScaleDPI.Register); 27 31 RegisterUnit('UTheme', @UTheme.Register); 32 RegisterUnit('UTranslator', @UTranslator.Register); 33 RegisterUnit('UAboutDialog', @UAboutDialog.Register); 28 34 end; 29 35 -
trunk/Packages/Common/Languages/UThreading.cs.po
r11 r25 11 11 12 12 #: uthreading.scurrentthreadnotfound 13 #, object-pascal-format 13 14 msgid "Current thread ID %d not found in virtual thread list." 14 15 msgstr "Aktuální vlákno ID %d nenalezeno v seznamu virtuálních vláken." -
trunk/Packages/Common/StopWatch.pas
r10 r25 5 5 6 6 uses 7 {$IFDEF W indows}Windows,{$ENDIF}7 {$IFDEF WINDOWS}Windows,{$ENDIF} 8 8 SysUtils, DateUtils; 9 9 … … 32 32 end; 33 33 34 34 35 implementation 35 36 … … 40 41 fIsRunning := False; 41 42 42 {$IFDEF W indows}43 {$IFDEF WINDOWS} 43 44 fIsHighResolution := QueryPerformanceFrequency(fFrequency) ; 44 45 {$ELSE} -
trunk/Packages/Common/UApplicationInfo.pas
r20 r25 1 1 unit UApplicationInfo; 2 3 {$mode delphi}4 2 5 3 interface 6 4 7 5 uses 8 SysUtils, Classes, Forms, URegistry, LCLType;6 SysUtils, Classes, Forms, URegistry, Controls, Graphics, LCLType; 9 7 10 8 type … … 15 13 private 16 14 FDescription: TTranslateString; 15 FIcon: TBitmap; 17 16 FIdentification: Byte; 18 17 FLicense: string; … … 33 32 public 34 33 constructor Create(AOwner: TComponent); override; 34 destructor Destroy; override; 35 35 property Version: string read GetVersion; 36 36 function GetRegistryContext: TRegistryContext; … … 47 47 property EmailContact: string read FEmailContact write FEmailContact; 48 48 property AppName: string read FAppName write FAppName; 49 property Description: string read FDescription write FDescription;49 property Description: TTranslateString read FDescription write FDescription; 50 50 property ReleaseDate: TDateTime read FReleaseDate write FReleaseDate; 51 51 property RegistryKey: string read FRegistryKey write FRegistryKey; 52 52 property RegistryRoot: TRegistryRoot read FRegistryRoot write FRegistryRoot; 53 53 property License: string read FLicense write FLicense; 54 property Icon: TBitmap read FIcon write FIcon; 54 55 end; 55 56 56 57 procedure Register; 57 58 59 58 60 implementation 59 61 60 62 procedure Register; 61 63 begin … … 74 76 constructor TApplicationInfo.Create(AOwner: TComponent); 75 77 begin 76 inherited Create(AOwner);78 inherited; 77 79 FVersionMajor := 1; 78 80 FIdentification := 1; … … 80 82 FRegistryKey := '\Software\' + FAppName; 81 83 FRegistryRoot := rrKeyCurrentUser; 84 FIcon := TBitmap.Create; 85 end; 86 87 destructor TApplicationInfo.Destroy; 88 begin 89 FreeAndNil(FIcon); 90 inherited; 82 91 end; 83 92 -
trunk/Packages/Common/UCommon.pas
r15 r25 1 1 unit UCommon; 2 2 3 {$mode delphi}4 5 3 interface 6 4 7 5 uses 8 {$ ifdef Windows}Windows,{$endif}9 {$ ifdef Linux}baseunix,{$endif}10 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 11 FileUtil ; //, ShFolder, ShellAPI;6 {$IFDEF WINDOWS}Windows,{$ENDIF} 7 {$IFDEF UNIX}baseunix,{$ENDIF} 8 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, Graphics, 9 FileUtil, Generics.Collections; //, ShFolder, ShellAPI; 12 10 13 11 type 14 12 TArrayOfByte = array of Byte; 15 TArrayOfString = array of string;16 13 TExceptionEvent = procedure(Sender: TObject; E: Exception) of object; 17 14 … … 28 25 unfDNSDomainName = 11); 29 26 27 TFilterMethod = function (FileName: string): Boolean of object; 28 TFileNameMethod = procedure (FileName: string) of object; 29 30 30 var 31 31 ExceptionHandler: TExceptionEvent; 32 32 DLLHandle1: HModule; 33 33 34 {$IFDEF Windows} 35 GetUserNameEx: procedure (NameFormat: DWORD; 36 lpNameBuffer: LPSTR; nSize: PULONG); stdcall; 37 {$ENDIF} 38 39 function IntToBin(Data: Int64; Count: Byte): string; 34 {$IFDEF WINDOWS} 35 GetUserNameEx: procedure (NameFormat: DWORD; 36 lpNameBuffer: LPSTR; nSize: PULONG); stdcall; 37 {$ENDIF} 38 39 const 40 clLightBlue = TColor($FF8080); 41 clLightGreen = TColor($80FF80); 42 clLightRed = TColor($8080FF); 43 44 function AddLeadingZeroes(const aNumber, Length : integer) : string; 40 45 function BinToInt(BinStr: string): Int64; 41 function TryHexToInt(Data: string; var Value: Integer): Boolean;42 function TryBinToInt(Data: string; var Value: Integer): Boolean;43 46 function BinToHexString(Source: AnsiString): string; 44 47 //function DelTree(DirName : string): Boolean; … … 46 49 function BCDToInt(Value: Byte): Byte; 47 50 function CompareByteArray(Data1, Data2: TArrayOfByte): Boolean; 51 procedure CopyStringArray(Dest: TStringArray; Source: array of string); 52 function CombinePaths(Path1, Path2: string): string; 53 function ComputerName: string; 54 procedure DeleteFiles(APath, AFileSpec: string); 55 function Explode(Separator: Char; Data: string): TStringArray; 56 procedure ExecuteProgram(Executable: string; Parameters: array of string); 57 procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog); 58 procedure FreeThenNil(var Obj); 59 function GetDirCount(Dir: string): Integer; 48 60 function GetUserName: string; 49 function LoggedOnUserNameEx(Format: TUserNameFormat): string;50 function SplitString(var Text: string; Count: Word): string;51 61 function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer; 52 62 function GetBit(Variable: QWord; Index: Byte): Boolean; 63 function GetStringPart(var Text: string; Separator: string): string; 64 function GenerateNewName(OldName: string): string; 65 function GetFileFilterItemExt(Filter: string; Index: Integer): string; 66 function IntToBin(Data: Int64; Count: Byte): string; 67 function Implode(Separator: Char; List: TList<string>): string; 68 function LastPos(const SubStr: String; const S: String): Integer; 69 function LoadFileToStr(const FileName: TFileName): AnsiString; 70 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 71 function MergeArray(A, B: array of string): TStringArray; 72 function OccurenceOfChar(What: Char; Where: string): Integer; 73 procedure OpenWebPage(URL: string); 74 procedure OpenEmail(Email: string); 75 procedure OpenFileInShell(FileName: string); 76 function PosFromIndex(SubStr: string; Text: string; 77 StartIndex: Integer): Integer; 78 function PosFromIndexReverse(SubStr: string; Text: string; 79 StartIndex: Integer): Integer; 80 function RemoveQuotes(Text: string): string; 81 procedure SaveStringToFile(S, FileName: string); 53 82 procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean); overload; 54 83 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload; 55 84 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload; 56 85 procedure SetBit(var Variable: Word; Index: Byte; State: Boolean); overload; 57 function AddLeadingZeroes(const aNumber, Length : integer) : string; 58 function LastPos(const SubStr: String; const S: String): Integer; 59 function GenerateNewName(OldName: string): string; 60 function GetFileFilterItemExt(Filter: string; Index: Integer): string; 61 procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog); 62 procedure DeleteFiles(APath, AFileSpec: string); 63 procedure OpenWebPage(URL: string); 64 procedure OpenFileInShell(FileName: string); 65 procedure ExecuteProgram(Executable: string; Parameters: array of string); 66 procedure FreeThenNil(var Obj); 67 function RemoveQuotes(Text: string): string; 68 function ComputerName: string; 69 function OccurenceOfChar(What: Char; Where: string): Integer; 70 function GetDirCount(Dir: string): Integer; 71 function MergeArray(A, B: array of string): TArrayOfString; 72 function LoadFileToStr(const FileName: TFileName): AnsiString; 86 procedure SearchFiles(AList: TStrings; Dir: string; 87 FilterMethod: TFilterMethod = nil; FileNameMethod: TFileNameMethod = nil); 88 function SplitString(var Text: string; Count: Word): string; 89 function StripTags(const S: string): string; 90 function TryHexToInt(Data: string; out Value: Integer): Boolean; 91 function TryBinToInt(Data: string; out Value: Integer): Boolean; 92 procedure SortStrings(Strings: TStrings); 73 93 74 94 … … 98 118 I: Integer; 99 119 begin 120 Result := ''; 100 121 for I := 1 to Length(Source) do begin 101 122 Result := Result + LowerCase(IntToHex(Ord(Source[I]), 2)); … … 230 251 end; 231 252 232 function TryHexToInt(Data: string; varValue: Integer): Boolean;253 function TryHexToInt(Data: string; out Value: Integer): Boolean; 233 254 var 234 255 I: Integer; … … 246 267 end; 247 268 248 function TryBinToInt(Data: string; varValue: Integer): Boolean;269 function TryBinToInt(Data: string; out Value: Integer): Boolean; 249 270 var 250 271 I: Integer; … … 274 295 end; 275 296 276 function Explode(Separator: char; Data: string): TArrayOfString; 277 begin 278 SetLength(Result, 0); 279 while Pos(Separator, Data) > 0 do begin 297 function Explode(Separator: Char; Data: string): TStringArray; 298 var 299 Index: Integer; 300 begin 301 Result := Default(TStringArray); 302 repeat 303 Index := Pos(Separator, Data); 304 if Index > 0 then begin 305 SetLength(Result, Length(Result) + 1); 306 Result[High(Result)] := Copy(Data, 1, Index - 1); 307 Delete(Data, 1, Index); 308 end else Break; 309 until False; 310 if Data <> '' then begin 280 311 SetLength(Result, Length(Result) + 1); 281 Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1); 282 Delete(Data, 1, Pos(Separator, Data)); 283 end; 284 SetLength(Result, Length(Result) + 1); 285 Result[High(Result)] := Data; 286 end; 287 288 {$IFDEF Windows} 312 Result[High(Result)] := Data; 313 end; 314 end; 315 316 function Implode(Separator: Char; List: TList<string>): string; 317 var 318 I: Integer; 319 begin 320 Result := ''; 321 for I := 0 to List.Count - 1 do begin 322 Result := Result + List[I]; 323 if I < List.Count - 1 then Result := Result + Separator; 324 end; 325 end; 326 327 {$IFDEF WINDOWS} 289 328 function GetUserName: string; 290 329 const … … 294 333 begin 295 334 L := MAX_USERNAME_LENGTH + 2; 335 Result := Default(string); 296 336 SetLength(Result, L); 297 337 if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin … … 307 347 end; 308 348 end; 309 {$ endif}349 {$ENDIF} 310 350 311 351 function ComputerName: string; 312 {$ ifdef mswindows}352 {$IFDEF WINDOWS} 313 353 const 314 354 INFO_BUFFER_SIZE = 32767; … … 325 365 end; 326 366 end; 327 {$ endif}328 {$ ifdef unix}367 {$ENDIF} 368 {$IFDEF UNIX} 329 369 var 330 370 Name: UtsName; 331 371 begin 372 Name := Default(UtsName); 332 373 fpuname(Name); 333 374 Result := Name.Nodename; 334 375 end; 335 {$ endif}336 337 {$ ifdef windows}376 {$ENDIF} 377 378 {$IFDEF WINDOWS} 338 379 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 339 380 const … … 413 454 procedure LoadLibraries; 414 455 begin 415 {$IFDEF W indows}456 {$IFDEF WINDOWS} 416 457 DLLHandle1 := LoadLibrary('secur32.dll'); 417 458 if DLLHandle1 <> 0 then … … 424 465 procedure FreeLibraries; 425 466 begin 426 {$IFDEF W indows}467 {$IFDEF WINDOWS} 427 468 if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1); 428 469 {$ENDIF} … … 457 498 end; 458 499 500 procedure OpenEmail(Email: string); 501 begin 502 OpenURL('mailto:' + Email); 503 end; 504 459 505 procedure OpenFileInShell(FileName: string); 460 506 begin … … 485 531 end; 486 532 487 function MergeArray(A, B: array of string): TArrayOfString; 488 var 489 I: Integer; 490 begin 533 function MergeArray(A, B: array of string): TStringArray; 534 var 535 I: Integer; 536 begin 537 Result := Default(TStringArray); 491 538 SetLength(Result, Length(A) + Length(B)); 492 539 for I := 0 to Length(A) - 1 do … … 514 561 end; 515 562 563 function DefaultSearchFilter(const FileName: string): Boolean; 564 begin 565 Result := True; 566 end; 567 568 procedure SaveStringToFile(S, FileName: string); 569 var 570 F: TextFile; 571 begin 572 AssignFile(F, FileName); 573 try 574 ReWrite(F); 575 Write(F, S); 576 finally 577 CloseFile(F); 578 end; 579 end; 580 581 procedure SearchFiles(AList: TStrings; Dir: string; 582 FilterMethod: TFilterMethod = nil; FileNameMethod: TFileNameMethod = nil); 583 var 584 SR: TSearchRec; 585 begin 586 Dir := IncludeTrailingPathDelimiter(Dir); 587 if FindFirst(Dir + '*', faAnyFile, SR) = 0 then 588 try 589 repeat 590 if (SR.Name = '.') or (SR.Name = '..') or (Assigned(FilterMethod) and (not FilterMethod(SR.Name) or 591 not FilterMethod(Copy(Dir, 3, Length(Dir)) + SR.Name))) then Continue; 592 if Assigned(FileNameMethod) then 593 FileNameMethod(Dir + SR.Name); 594 AList.Add(Dir + SR.Name); 595 if (SR.Attr and faDirectory) <> 0 then 596 SearchFiles(AList, Dir + SR.Name, FilterMethod); 597 until FindNext(SR) <> 0; 598 finally 599 FindClose(SR); 600 end; 601 end; 602 603 function GetStringPart(var Text: string; Separator: string): string; 604 var 605 P: Integer; 606 begin 607 P := Pos(Separator, Text); 608 if P > 0 then begin 609 Result := Copy(Text, 1, P - 1); 610 Delete(Text, 1, P - 1 + Length(Separator)); 611 end else begin 612 Result := Text; 613 Text := ''; 614 end; 615 Result := Trim(Result); 616 Text := Trim(Text); 617 end; 618 619 function StripTags(const S: string): string; 620 var 621 Len: Integer; 622 623 function ReadUntil(const ReadFrom: Integer; const C: Char): Integer; 624 var 625 J: Integer; 626 begin 627 for J := ReadFrom to Len do 628 if (S[j] = C) then 629 begin 630 Result := J; 631 Exit; 632 end; 633 Result := Len + 1; 634 end; 635 636 var 637 I, APos: Integer; 638 begin 639 Len := Length(S); 640 I := 0; 641 Result := ''; 642 while (I <= Len) do begin 643 Inc(I); 644 APos := ReadUntil(I, '<'); 645 Result := Result + Copy(S, I, APos - i); 646 I := ReadUntil(APos + 1, '>'); 647 end; 648 end; 649 650 function PosFromIndex(SubStr: string; Text: string; 651 StartIndex: Integer): Integer; 652 var 653 I, MaxLen: SizeInt; 654 Ptr: PAnsiChar; 655 begin 656 Result := 0; 657 if (StartIndex < 1) or (StartIndex > Length(Text) - Length(SubStr)) then Exit; 658 if Length(SubStr) > 0 then begin 659 MaxLen := Length(Text) - Length(SubStr) + 1; 660 I := StartIndex; 661 Ptr := @Text[StartIndex]; 662 while (I <= MaxLen) do begin 663 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 664 Result := I; 665 Exit; 666 end; 667 Inc(I); 668 Inc(Ptr); 669 end; 670 end; 671 end; 672 673 function PosFromIndexReverse(SubStr: string; Text: string; 674 StartIndex: Integer): Integer; 675 var 676 I: SizeInt; 677 Ptr: PAnsiChar; 678 begin 679 Result := 0; 680 if (StartIndex < 1) or (StartIndex > Length(Text)) then Exit; 681 if Length(SubStr) > 0 then begin 682 I := StartIndex; 683 Ptr := @Text[StartIndex]; 684 while (I > 0) do begin 685 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 686 Result := I; 687 Exit; 688 end; 689 Dec(I); 690 Dec(Ptr); 691 end; 692 end; 693 end; 694 695 procedure CopyStringArray(Dest: TStringArray; Source: array of string); 696 var 697 I: Integer; 698 begin 699 SetLength(Dest, Length(Source)); 700 for I := 0 to Length(Dest) - 1 do 701 Dest[I] := Source[I]; 702 end; 703 704 function CombinePaths(Path1, Path2: string): string; 705 begin 706 Result := Path1; 707 if Result <> '' then Result := Result + DirectorySeparator + Path2 708 else Result := Path2; 709 end; 710 711 procedure SortStrings(Strings: TStrings); 712 var 713 Tmp: TStringList; 714 begin 715 Strings.BeginUpdate; 716 try 717 if Strings is TStringList then begin 718 TStringList(Strings).Sort; 719 end else begin 720 Tmp := TStringList.Create; 721 try 722 Tmp.Assign(Strings); 723 Tmp.Sort; 724 Strings.Assign(Tmp); 725 finally 726 Tmp.Free; 727 end; 728 end; 729 finally 730 Strings.EndUpdate; 731 end; 732 end; 516 733 517 734 -
trunk/Packages/Common/UDebugLog.pas
r15 r25 1 1 unit UDebugLog; 2 3 {$mode delphi}4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, FileUtil, SpecializedList, SyncObjs;6 Classes, SysUtils, FileUtil, Generics.Collections, SyncObjs; 9 7 10 8 type … … 15 13 Group: string; 16 14 Text: string; 15 end; 16 17 TDebugLogItems = class(TObjectList<TDebugLogItem>) 17 18 end; 18 19 … … 29 30 procedure SetMaxCount(const AValue: Integer); 30 31 public 31 Items: T ListObject;32 Items: TDebugLogItems; 32 33 Lock: TCriticalSection; 33 34 procedure Add(Text: string; Group: string = ''); … … 44 45 45 46 procedure Register; 47 46 48 47 49 implementation … … 104 106 if ExtractFileDir(FileName) <> '' then 105 107 ForceDirectories(ExtractFileDir(FileName)); 106 if FileExists(FileName) then LogFile := TFileStream.Create( UTF8Decode(FileName), fmOpenWrite)107 else LogFile := TFileStream.Create( UTF8Decode(FileName), fmCreate);108 if FileExists(FileName) then LogFile := TFileStream.Create(FileName, fmOpenWrite) 109 else LogFile := TFileStream.Create(FileName, fmCreate); 108 110 LogFile.Seek(0, soFromEnd); 109 111 Text := FormatDateTime('hh:nn:ss.zzz', Now) + ': ' + Text + LineEnding; … … 117 119 begin 118 120 inherited; 119 Items := T ListObject.Create;121 Items := TDebugLogItems.Create; 120 122 Lock := TCriticalSection.Create; 121 123 MaxCount := 100; … … 126 128 destructor TDebugLog.Destroy; 127 129 begin 128 Items.Free;129 Lock.Free;130 FreeAndNil(Items); 131 FreeAndNil(Lock); 130 132 inherited; 131 133 end; -
trunk/Packages/Common/UDelay.pas
r10 r25 1 1 unit UDelay; 2 3 {$mode delphi}4 2 5 3 interface -
trunk/Packages/Common/UFindFile.pas
r15 r25 24 24 25 25 uses 26 SysUtils, Classes, Graphics, Controls, Forms, Dialogs , FileCtrl;26 SysUtils, Classes, Graphics, Controls, Forms, Dialogs; 27 27 28 28 type … … 35 35 private 36 36 s : TStringList; 37 38 37 fSubFolder : boolean; 39 38 fAttr: TFileAttrib; 40 39 fPath : string; 41 40 fFileMask : string; 42 43 41 procedure SetPath(Value: string); 44 42 procedure FileSearch(const inPath : string); … … 46 44 constructor Create(AOwner: TComponent); override; 47 45 destructor Destroy; override; 48 49 46 function SearchForFiles: TStringList; 50 47 published … … 59 56 FilterAll = '*.*'; 60 57 {$ENDIF} 61 {$IFDEF LINUX}58 {$IFDEF UNIX} 62 59 FilterAll = '*'; 63 60 {$ENDIF} 64 61 65 62 procedure Register; 63 66 64 67 65 implementation … … 87 85 begin 88 86 s.Free; 89 inherited Destroy;87 inherited; 90 88 end; 91 89 … … 117 115 Attr := 0; 118 116 if ffaReadOnly in FileAttr then Attr := Attr + faReadOnly; 119 if ffaHidden in FileAttr then Attr := Attr + faHidden;120 if ffaSysFile in FileAttr then Attr := Attr + faSysFile;121 if ffaVolumeID in FileAttr then Attr := Attr + faVolumeID;117 if ffaHidden in FileAttr then Attr := Attr + 2; //faHidden; use constant to avoid platform warning 118 if ffaSysFile in FileAttr then Attr := Attr + 4; //faSysFile; use constant to avoid platform warning 119 // Deprecated: if ffaVolumeID in FileAttr then Attr := Attr + faVolumeID; 122 120 if ffaDirectory in FileAttr then Attr := Attr + faDirectory; 123 121 if ffaArchive in FileAttr then Attr := Attr + faArchive; 124 122 if ffaAnyFile in FileAttr then Attr := Attr + faAnyFile; 125 123 126 if SysUtils.FindFirst( UTF8Decode(inPath + FileMask), Attr, Rec) = 0 then124 if SysUtils.FindFirst(inPath + FileMask, Attr, Rec) = 0 then 127 125 try 128 126 repeat 129 s.Add(inPath + UTF8Encode(Rec.Name));127 s.Add(inPath + Rec.Name); 130 128 until SysUtils.FindNext(Rec) <> 0; 131 129 finally … … 135 133 If not InSubFolders then Exit; 136 134 137 if SysUtils.FindFirst( UTF8Decode(inPath + FilterAll), faDirectory, Rec) = 0 then135 if SysUtils.FindFirst(inPath + FilterAll, faDirectory, Rec) = 0 then 138 136 try 139 137 repeat 140 138 if ((Rec.Attr and faDirectory) > 0) and (Rec.Name <> '.') 141 139 and (Rec.Name <> '..') then 142 FileSearch(IncludeTrailingBackslash(inPath + UTF8Encode(Rec.Name)));140 FileSearch(IncludeTrailingBackslash(inPath + Rec.Name)); 143 141 until SysUtils.FindNext(Rec) <> 0; 144 142 finally -
trunk/Packages/Common/UJobProgressView.lfm
r15 r25 1 1 object FormJobProgressView: TFormJobProgressView 2 2 Left = 467 3 Height = 2463 Height = 414 4 4 Top = 252 5 Width = 3285 Width = 647 6 6 BorderIcons = [biSystemMenu] 7 ClientHeight = 246 8 ClientWidth = 328 9 Font.Height = -11 10 Font.Name = 'MS Sans Serif' 7 ClientHeight = 414 8 ClientWidth = 647 9 DesignTimePPI = 144 11 10 OnClose = FormClose 12 11 OnCloseQuery = FormCloseQuery 13 12 OnCreate = FormCreate 14 OnDestroy = FormDestroy 13 OnHide = FormHide 14 OnShow = FormShow 15 15 Position = poScreenCenter 16 LCLVersion = ' 1.6.0.4'16 LCLVersion = '2.2.0.4' 17 17 object PanelOperationsTitle: TPanel 18 18 Left = 0 19 Height = 2419 Height = 38 20 20 Top = 0 21 Width = 32821 Width = 647 22 22 Align = alTop 23 23 BevelOuter = bvNone 24 ClientHeight = 2425 ClientWidth = 32824 ClientHeight = 38 25 ClientWidth = 647 26 26 FullRepaint = False 27 27 TabOrder = 0 28 28 object LabelOperation: TLabel 29 Left = 830 Height = 1331 Top = 832 Width = 6629 Left = 10 30 Height = 26 31 Top = 10 32 Width = 99 33 33 Caption = 'Operations:' 34 Font.Height = -1135 Font.Name = 'MS Sans Serif'36 Font.Style = [fsBold]37 ParentColor = False38 34 ParentFont = False 39 35 end … … 41 37 object PanelLog: TPanel 42 38 Left = 0 43 Height = 1 2244 Top = 12445 Width = 32839 Height = 161 40 Top = 253 41 Width = 647 46 42 Align = alClient 47 43 BevelOuter = bvSpace 48 ClientHeight = 1 2249 ClientWidth = 32844 ClientHeight = 161 45 ClientWidth = 647 50 46 TabOrder = 1 51 47 object MemoLog: TMemo 52 Left = 853 Height = 1 0654 Top = 855 Width = 31248 Left = 10 49 Height = 141 50 Top = 10 51 Width = 627 56 52 Anchors = [akTop, akLeft, akRight, akBottom] 57 53 ReadOnly = True … … 62 58 object PanelProgress: TPanel 63 59 Left = 0 64 Height = 3865 Top = 5066 Width = 32860 Height = 65 61 Top = 126 62 Width = 647 67 63 Align = alTop 68 64 BevelOuter = bvNone 69 ClientHeight = 3870 ClientWidth = 32865 ClientHeight = 65 66 ClientWidth = 647 71 67 TabOrder = 2 72 68 object ProgressBarPart: TProgressBar 73 Left = 874 Height = 1775 Top = 1676 Width = 31269 Left = 12 70 Height = 29 71 Top = 29 72 Width = 628 77 73 Anchors = [akTop, akLeft, akRight] 78 74 TabOrder = 0 79 75 end 80 76 object LabelEstimatedTimePart: TLabel 81 Left = 882 Height = 1377 Left = 10 78 Height = 26 83 79 Top = -2 84 Width = 7180 Width = 132 85 81 Caption = 'Estimated time:' 86 ParentColor = False87 82 end 88 83 end 89 84 object PanelOperations: TPanel 90 85 Left = 0 91 Height = 2692 Top = 2493 Width = 32886 Height = 50 87 Top = 76 88 Width = 647 94 89 Align = alTop 95 90 BevelOuter = bvNone 96 ClientHeight = 2697 ClientWidth = 32891 ClientHeight = 50 92 ClientWidth = 647 98 93 FullRepaint = False 99 94 TabOrder = 3 100 95 object ListViewJobs: TListView 101 Left = 8102 Height = 16103 Top = 5104 Width = 31296 Left = 10 97 Height = 38 98 Top = 6 99 Width = 627 105 100 Anchors = [akTop, akLeft, akRight, akBottom] 106 101 AutoWidthLastColumn = True … … 109 104 Columns = < 110 105 item 111 Width = 312106 Width = 614 112 107 end> 113 108 OwnerData = True … … 122 117 object PanelProgressTotal: TPanel 123 118 Left = 0 124 Height = 36125 Top = 88126 Width = 328119 Height = 62 120 Top = 191 121 Width = 647 127 122 Align = alTop 128 123 BevelOuter = bvNone 129 ClientHeight = 36130 ClientWidth = 328124 ClientHeight = 62 125 ClientWidth = 647 131 126 TabOrder = 4 132 127 object LabelEstimatedTimeTotal: TLabel 133 Left = 8134 Height = 13128 Left = 10 129 Height = 26 135 130 Top = 0 136 Width = 97131 Width = 178 137 132 Caption = 'Total estimated time:' 138 ParentColor = False139 133 end 140 134 object ProgressBarTotal: TProgressBar 141 Left = 8142 Height = 16143 Top = 16144 Width = 312135 Left = 10 136 Height = 29 137 Top = 29 138 Width = 627 145 139 Anchors = [akTop, akLeft, akRight] 146 140 TabOrder = 0 147 141 end 148 142 end 143 object PanelText: TPanel 144 Left = 0 145 Height = 38 146 Top = 38 147 Width = 647 148 Align = alTop 149 BevelOuter = bvNone 150 ClientHeight = 38 151 ClientWidth = 647 152 TabOrder = 5 153 object LabelText: TLabel 154 Left = 10 155 Height = 29 156 Top = 10 157 Width = 630 158 Anchors = [akTop, akLeft, akRight] 159 AutoSize = False 160 end 161 end 149 162 object ImageList1: TImageList 150 BkColor = clForeground 151 left = 200 152 top = 8 163 Left = 240 164 Top = 10 153 165 Bitmap = { 154 4C69020000001000000010000000FF00FF00FF00FF00FF00FF00FF00FF00FF00 155 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 156 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 157 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 158 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 159 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 160 FF00000000FF000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 161 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF000000 162 00FF000000FF000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 163 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF0000 164 00FF000000FF000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 165 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF0000 166 00FF000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 167 FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF000000FF0000 168 00FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FFFF00FF00FF00 169 FF00FF00FF00FF00FF00FF00FF00000000FF000000FF000000FF000000FFFF00 170 FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF000000FFFF00 171 FF00FF00FF00FF00FF00000000FF000000FF000000FF000000FFFF00FF00FF00 172 FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF000000FF0000 173 00FFFF00FF00000000FF000000FF000000FF000000FFFF00FF00FF00FF00FF00 174 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF0000 175 00FF000000FF000000FF000000FF000000FFFF00FF00FF00FF00FF00FF00FF00 176 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF0000 177 00FF000000FF000000FF000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00 178 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF000000 179 00FF000000FF000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 180 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 181 FF00000000FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 182 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 183 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 184 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 185 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 186 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 187 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 188 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 189 FF00FF00FF00FF00FF00FF00FF00000000FFFF00FF00FF00FF00FF00FF00FF00 190 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 191 FF00FF00FF00FF00FF00FF00FF00000000FF000000FFFF00FF00FF00FF00FF00 192 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 193 FF00FF00FF00FF00FF00FF00FF00000000FF000084FF000000FFFF00FF00FF00 194 FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF000000FF0000 195 00FF000000FF000000FF000000FF000000FF0000FFFF000084FF000000FFFF00 196 FF00FF00FF00FF00FF00FF00FF00FF00FF00000000FF0000FFFF0000FFFF0000 197 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF000084FF0000 198 00FFFF00FF00FF00FF00FF00FF00FF00FF00000000FF0000FFFF0000FFFF0000 199 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 200 84FF000000FFFF00FF00FF00FF00FF00FF00000000FF0000FFFF0000FFFF0000 201 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 202 FFFF000084FF000000FFFF00FF00FF00FF00000000FF0000FFFF0000FFFF0000 203 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 204 84FF000000FFFF00FF00FF00FF00FF00FF00000000FF0000FFFF0000FFFF0000 205 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF000084FF0000 206 00FFFF00FF00FF00FF00FF00FF00FF00FF00000000FF000000FF000000FF0000 207 00FF000000FF000000FF000000FF000000FF0000FFFF000084FF000000FFFF00 208 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 209 FF00FF00FF00FF00FF00FF00FF00000000FF000084FF000000FFFF00FF00FF00 210 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 211 FF00FF00FF00FF00FF00FF00FF00000000FF000000FFFF00FF00FF00FF00FF00 212 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 213 FF00FF00FF00FF00FF00FF00FF00000000FFFF00FF00FF00FF00FF00FF00FF00 214 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 215 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 216 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 217 FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 218 FF00FF00FF00FF00FF00FF00FF00 166 4C7A0200000010000000100000006A0000000000000078DAE593490E00100C45 167 7B78F72E5684A63A1142C382BE4F0708F89C955117F4B016BE67B5FC6E96DB97 168 B0D4B9F4CD949F36DED1DF922B0F1BD11FAB5AFC68DE5C44D40220A9FA779EC8 169 6A349FD5A435E43CADA1E3678D73F773F1DBF3EFADFFEEFEBBF97F6696BE9D36 219 170 } 220 171 end … … 223 174 Interval = 100 224 175 OnTimer = TimerUpdateTimer 225 left = 264226 top = 8176 Left = 384 177 Top = 10 227 178 end 228 179 end -
trunk/Packages/Common/UJobProgressView.pas
r15 r25 1 1 unit UJobProgressView; 2 3 {$MODE Delphi}4 2 5 3 interface … … 7 5 uses 8 6 SysUtils, Variants, Classes, Graphics, Controls, Forms, Syncobjs, 9 Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading,7 Dialogs, ComCtrls, StdCtrls, ExtCtrls, Generics.Collections, UThreading, Math, 10 8 DateUtils; 11 9 … … 13 11 EstimatedTimeShowTreshold = 4; 14 12 EstimatedTimeShowTresholdTotal = 1; 15 MemoLogHeight = 200;16 13 UpdateInterval = 100; // ms 17 14 … … 24 21 FLock: TCriticalSection; 25 22 FOnChange: TNotifyEvent; 23 FText: string; 26 24 FValue: Integer; 27 25 FMax: Integer; 28 26 procedure SetMax(const AValue: Integer); 27 procedure SetText(AValue: string); 29 28 procedure SetValue(const AValue: Integer); 30 29 public … … 35 34 property Value: Integer read FValue write SetValue; 36 35 property Max: Integer read FMax write SetMax; 36 property Text: string read FText write SetText; 37 37 property OnChange: TNotifyEvent read FOnChange write FOnChange; 38 38 end; … … 69 69 end; 70 70 71 TJobs = class(TObjectList<TJob>) 72 end; 73 71 74 TJobThread = class(TListedThread) 72 75 procedure Execute; override; … … 80 83 TFormJobProgressView = class(TForm) 81 84 ImageList1: TImageList; 85 LabelText: TLabel; 82 86 Label2: TLabel; 83 87 LabelOperation: TLabel; … … 86 90 ListViewJobs: TListView; 87 91 MemoLog: TMemo; 92 PanelText: TPanel; 88 93 PanelProgressTotal: TPanel; 89 94 PanelOperationsTitle: TPanel; … … 94 99 ProgressBarTotal: TProgressBar; 95 100 TimerUpdate: TTimer; 101 procedure FormHide(Sender: TObject); 102 procedure FormShow(Sender: TObject); 103 procedure ReloadJobList; 96 104 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 97 procedure FormDestroy(Sender: TObject);98 105 procedure ListViewJobsData(Sender: TObject; Item: TListItem); 99 106 procedure TimerUpdateTimer(Sender: TObject); 100 107 procedure FormCreate(Sender: TObject); 101 108 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 109 procedure UpdateHeight; 102 110 public 103 111 JobProgressView: TJobProgressView; … … 118 126 TotalStartTime: TDateTime; 119 127 Log: TStringList; 128 FForm: TFormJobProgressView; 120 129 procedure SetTerminate(const AValue: Boolean); 121 130 procedure UpdateProgress; 122 procedure ReloadJobList;123 procedure StartJobs;124 procedure UpdateHeight;125 131 procedure JobProgressChange(Sender: TObject); 126 132 public 127 Form: TFormJobProgressView; 128 Jobs: TObjectList; // TListObject<TJob> 133 Jobs: TJobs; 129 134 CurrentJob: TJob; 130 135 CurrentJobIndex: Integer; … … 132 137 destructor Destroy; override; 133 138 procedure Clear; 134 procedureAddJob(Title: string; Method: TJobProgressViewMethod;135 NoThreaded: Boolean = False; WaitFor: Boolean = False) ;136 procedure Start (AAutoClose: Boolean = True);139 function AddJob(Title: string; Method: TJobProgressViewMethod; 140 NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob; 141 procedure Start; 137 142 procedure Stop; 138 143 procedure TermSleep(Delay: Integer); 144 property Form: TFormJobProgressView read FForm; 139 145 property Terminate: Boolean read FTerminate write SetTerminate; 140 146 published … … 156 162 SExecuted = 'Executed'; 157 163 164 158 165 implementation 159 166 … … 166 173 STotalEstimatedTime = 'Total estimated time: %s'; 167 174 SFinished = 'Finished'; 168 SOperations = 'Operations';169 175 170 176 procedure Register; … … 172 178 RegisterComponents('Common', [TJobProgressView]); 173 179 end; 180 181 { TJobThread } 174 182 175 183 procedure TJobThread.Execute; … … 190 198 end; 191 199 192 procedure TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod; 193 NoThreaded: Boolean = False; WaitFor: Boolean = False); 200 { TFormJobProgressView } 201 202 procedure TFormJobProgressView.UpdateHeight; 194 203 var 195 NewJob: TJob; 196 begin 197 NewJob := TJob.Create; 198 NewJob.ProgressView := Self; 199 NewJob.Title := Title; 200 NewJob.Method := Method; 201 NewJob.NoThreaded := NoThreaded; 202 NewJob.WaitFor := WaitFor; 203 NewJob.Progress.Max := 100; 204 NewJob.Progress.Reset; 205 NewJob.Progress.OnChange := JobProgressChange; 206 Jobs.Add(NewJob); 204 H: Integer; 205 PanelOperationsVisible: Boolean; 206 PanelOperationsHeight: Integer; 207 PanelProgressVisible: Boolean; 208 PanelProgressTotalVisible: Boolean; 209 PanelLogVisible: Boolean; 210 MemoLogHeight: Integer = 200; 211 I: Integer; 212 ItemRect: TRect; 213 MaxH: Integer; 214 begin 215 H := PanelOperationsTitle.Height; 216 PanelOperationsVisible := JobProgressView.Jobs.Count > 0; 217 if PanelOperationsVisible <> PanelOperations.Visible then 218 PanelOperations.Visible := PanelOperationsVisible; 219 if ListViewJobs.Items.Count > 0 then begin 220 Maxh := 0; 221 for I := 0 to ListViewJobs.Items.Count - 1 do 222 begin 223 ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds); 224 Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top)); 225 end; 226 PanelOperationsHeight := Scale96ToScreen(12) + Maxh; 227 end else PanelOperationsHeight := Scale96ToScreen(8); 228 if PanelOperationsHeight <> PanelOperations.Height then 229 PanelOperations.Height := PanelOperationsHeight; 230 if PanelOperationsVisible then 231 H := H + PanelOperations.Height; 232 233 PanelProgressVisible := (JobProgressView.Jobs.Count > 0) and not JobProgressView.Finished; 234 if PanelProgressVisible <> PanelProgress.Visible then 235 PanelProgress.Visible := PanelProgressVisible; 236 if PanelProgressVisible then 237 H := H + PanelProgress.Height; 238 PanelProgressTotalVisible := (JobProgressView.Jobs.Count > 1) and not JobProgressView.Finished; 239 if PanelProgressTotalVisible <> PanelProgressTotal.Visible then 240 PanelProgressTotal.Visible := PanelProgressTotalVisible; 241 if PanelProgressTotalVisible then 242 H := H + PanelProgressTotal.Height; 243 Constraints.MinHeight := H; 244 PanelLogVisible := MemoLog.Lines.Count > 0; 245 if PanelLogVisible <> PanelLog.Visible then 246 PanelLog.Visible := PanelLogVisible; 247 if PanelLogVisible then 248 H := H + Scale96ToScreen(MemoLogHeight); 249 if PanelText.Visible then 250 H := H + PanelText.Height; 251 if Height <> H then begin 252 Height := H; 253 Top := (Screen.Height - H) div 2; 254 end; 255 end; 256 257 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject); 258 var 259 ProgressBarPartVisible: Boolean; 260 ProgressBarTotalVisible: Boolean; 261 begin 262 JobProgressView.UpdateProgress; 263 if Visible and (not ProgressBarPart.Visible) and 264 Assigned(JobProgressView.CurrentJob) and 265 (JobProgressView.CurrentJob.Progress.Value > 0) then begin 266 ProgressBarPartVisible := True; 267 if ProgressBarPartVisible <> ProgressBarPart.Visible then 268 ProgressBarPart.Visible := ProgressBarPartVisible; 269 ProgressBarTotalVisible := True; 270 if ProgressBarTotalVisible <> ProgressBarTotal.Visible then 271 ProgressBarTotal.Visible := ProgressBarTotalVisible; 272 end; 273 if not Visible then begin 274 TimerUpdate.Interval := UpdateInterval; 275 if not JobProgressView.OwnerDraw then Show; 276 end; 277 if Assigned(JobProgressView.CurrentJob) then begin 278 LabelText.Caption := JobProgressView.CurrentJob.Progress.Text; 279 if LabelText.Caption <> '' then begin 280 PanelText.Visible := True; 281 UpdateHeight; 282 end; 283 end; 284 end; 285 286 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem); 287 begin 288 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then 289 with JobProgressView.Jobs[Item.Index] do begin 290 Item.Caption := Title; 291 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1 292 else if Finished then Item.ImageIndex := 0 293 else Item.ImageIndex := 2; 294 Item.Data := JobProgressView.Jobs[Item.Index]; 295 end; 296 end; 297 298 procedure TFormJobProgressView.FormClose(Sender: TObject; 299 var CloseAction: TCloseAction); 300 begin 301 end; 302 303 procedure TFormJobProgressView.FormCreate(Sender: TObject); 304 begin 305 Caption := SPleaseWait; 306 try 307 //Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) + 308 // DirectorySeparator + 'horse.avi'; 309 //Animate1.Active := True; 310 except 311 312 end; 313 end; 314 315 procedure TFormJobProgressView.ReloadJobList; 316 begin 317 // Workaround for not showing first line 318 //Form.ListViewJobs.Items.Count := Jobs.Count + 1; 319 //Form.ListViewJobs.Refresh; 320 321 if ListViewJobs.Items.Count <> JobProgressView.Jobs.Count then 322 ListViewJobs.Items.Count := JobProgressView.Jobs.Count; 323 ListViewJobs.Refresh; 324 Application.ProcessMessages; 325 UpdateHeight; 326 end; 327 328 procedure TFormJobProgressView.FormShow(Sender: TObject); 329 begin 330 ReloadJobList; 331 end; 332 333 procedure TFormJobProgressView.FormHide(Sender: TObject); 334 begin 335 JobProgressView.Jobs.Clear; 336 ReloadJobList; 337 end; 338 339 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 340 begin 341 CanClose := JobProgressView.Finished; 342 JobProgressView.Terminate := True; 343 Caption := SPleaseWait + STerminate; 344 end; 345 346 347 { TJobProgressView } 348 349 function TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod; 350 NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob; 351 begin 352 Result := TJob.Create; 353 Result.ProgressView := Self; 354 Result.Title := Title; 355 Result.Method := Method; 356 Result.NoThreaded := NoThreaded; 357 Result.WaitFor := WaitFor; 358 Result.Progress.Max := 100; 359 Result.Progress.Reset; 360 Result.Progress.OnChange := JobProgressChange; 361 Jobs.Add(Result); 207 362 //ReloadJobList; 208 363 end; 209 364 210 procedure TJobProgressView.Start(AAutoClose: Boolean = True); 211 begin 212 AutoClose := AAutoClose; 213 StartJobs; 214 end; 215 216 procedure TJobProgressView.StartJobs; 365 procedure TJobProgressView.Start; 217 366 var 218 367 I: Integer; … … 229 378 Form.MemoLog.Clear; 230 379 380 Form.PanelText.Visible := False; 231 381 Form.LabelEstimatedTimePart.Visible := False; 232 382 Form.LabelEstimatedTimeTotal.Visible := False; … … 249 399 I := 0; 250 400 while I < Jobs.Count do 251 with TJob(Jobs[I])do begin401 with Jobs[I] do begin 252 402 CurrentJobIndex := I; 253 CurrentJob := TJob(Jobs[I]);403 CurrentJob := Jobs[I]; 254 404 JobProgressChange(Self); 255 405 StartTime := Now; … … 258 408 Form.ProgressBarPart.Visible := False; 259 409 //Show; 260 ReloadJobList;410 Form.ReloadJobList; 261 411 Application.ProcessMessages; 262 412 if NoThreaded then begin … … 264 414 Method(CurrentJob); 265 415 end else begin 416 Thread := TJobThread.Create(True); 266 417 try 267 Thread := TJobThread.Create(True);268 418 with Thread do begin 269 419 FreeOnTerminate := False; … … 296 446 //if Visible then Hide; 297 447 Form.MemoLog.Lines.Assign(Log); 298 if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin448 if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin 299 449 Form.Hide; 300 450 end; 301 Clear;451 if not Form.Visible then Clear; 302 452 Form.Caption := SFinished; 303 453 //LabelEstimatedTimePart.Visible := False; 304 454 Finished := True; 305 455 CurrentJobIndex := -1; 306 ReloadJobList; 307 end; 308 end; 309 310 procedure TJobProgressView.UpdateHeight; 311 var 312 H: Integer; 313 PanelOperationsVisible: Boolean; 314 PanelOperationsHeight: Integer; 315 PanelProgressVisible: Boolean; 316 PanelProgressTotalVisible: Boolean; 317 PanelLogVisible: Boolean; 318 begin 319 with Form do begin 320 H := PanelOperationsTitle.Height; 321 PanelOperationsVisible := Jobs.Count > 0; 322 if PanelOperationsVisible <> PanelOperations.Visible then 323 PanelOperations.Visible := PanelOperationsVisible; 324 PanelOperationsHeight := 8 + 18 * Jobs.Count; 325 if PanelOperationsHeight <> PanelOperations.Height then 326 PanelOperations.Height := PanelOperationsHeight; 327 if PanelOperationsVisible then 328 H := H + PanelOperations.Height; 329 330 PanelProgressVisible := (Jobs.Count > 0) and not Finished; 331 if PanelProgressVisible <> PanelProgress.Visible then 332 PanelProgress.Visible := PanelProgressVisible; 333 if PanelProgressVisible then 334 H := H + PanelProgress.Height; 335 PanelProgressTotalVisible := (Jobs.Count > 1) and not Finished; 336 if PanelProgressTotalVisible <> PanelProgressTotal.Visible then 337 PanelProgressTotal.Visible := PanelProgressTotalVisible; 338 if PanelProgressTotalVisible then 339 H := H + PanelProgressTotal.Height; 340 Constraints.MinHeight := H; 341 PanelLogVisible := MemoLog.Lines.Count > 0; 342 if PanelLogVisible <> PanelLog.Visible then 343 PanelLog.Visible := PanelLogVisible; 344 if PanelLogVisible then 345 H := H + MemoLogHeight; 346 if Height <> H then Height := H; 456 Form.ReloadJobList; 347 457 end; 348 458 end; … … 352 462 if Assigned(FOnOwnerDraw) then 353 463 FOnOwnerDraw(Self); 354 end;355 356 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject);357 var358 ProgressBarPartVisible: Boolean;359 ProgressBarTotalVisible: Boolean;360 begin361 JobProgressView.UpdateProgress;362 if Visible and (not ProgressBarPart.Visible) and363 Assigned(JobProgressView.CurrentJob) and364 (JobProgressView.CurrentJob.Progress.Value > 0) then begin365 ProgressBarPartVisible := True;366 if ProgressBarPartVisible <> ProgressBarPart.Visible then367 ProgressBarPart.Visible := ProgressBarPartVisible;368 ProgressBarTotalVisible := True;369 if ProgressBarTotalVisible <> ProgressBarTotal.Visible then370 ProgressBarTotal.Visible := ProgressBarTotalVisible;371 end;372 if not Visible then begin373 TimerUpdate.Interval := UpdateInterval;374 if not JobProgressView.OwnerDraw then Show;375 end;376 end;377 378 procedure TFormJobProgressView.FormDestroy(Sender:TObject);379 begin380 end;381 382 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem);383 begin384 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then385 with TJob(JobProgressView.Jobs[Item.Index]) do begin386 Item.Caption := Title;387 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1388 else if Finished then Item.ImageIndex := 0389 else Item.ImageIndex := 2;390 Item.Data := JobProgressView.Jobs[Item.Index];391 end;392 end;393 394 procedure TFormJobProgressView.FormClose(Sender: TObject;395 var CloseAction: TCloseAction);396 begin397 ListViewJobs.Clear;398 end;399 400 procedure TFormJobProgressView.FormCreate(Sender: TObject);401 begin402 Caption := SPleaseWait;403 try404 //Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) +405 // DirectorySeparator + 'horse.avi';406 //Animate1.Active := True;407 except408 409 end;410 464 end; 411 465 … … 428 482 end; 429 483 430 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean);431 begin432 CanClose := JobProgressView.Finished;433 JobProgressView.Terminate := True;434 Caption := SPleaseWait + STerminate;435 end;436 437 484 procedure TJobProgressView.SetTerminate(const AValue: Boolean); 438 485 var … … 441 488 if AValue = FTerminate then Exit; 442 489 for I := 0 to Jobs.Count - 1 do 443 TJob(Jobs[I]).Terminate := AValue;490 Jobs[I].Terminate := AValue; 444 491 FTerminate := AValue; 445 492 end; … … 490 537 end; 491 538 492 procedure TJobProgressView.ReloadJobList;493 begin494 UpdateHeight;495 // Workaround for not showing first line496 Form.ListViewJobs.Items.Count := Jobs.Count + 1;497 Form.ListViewJobs.Refresh;498 499 if Form.ListViewJobs.Items.Count <> Jobs.Count then500 Form.ListViewJobs.Items.Count := Jobs.Count;501 Form.ListViewJobs.Refresh;502 //Application.ProcessMessages;503 end;504 505 539 constructor TJobProgressView.Create(TheOwner: TComponent); 506 540 begin 507 541 inherited; 508 542 if not (csDesigning in ComponentState) then begin 509 F orm := TFormJobProgressView.Create(Self);510 F orm.JobProgressView := Self;511 end; 512 Jobs := T ObjectList.Create;543 FForm := TFormJobProgressView.Create(Self); 544 FForm.JobProgressView := Self; 545 end; 546 Jobs := TJobs.Create; 513 547 Log := TStringList.Create; 514 548 //PanelOperationsTitle.Height := 80; 515 ShowDelay := 0; //1000; // ms 549 AutoClose := True; 550 ShowDelay := 0; 516 551 end; 517 552 … … 519 554 begin 520 555 Jobs.Clear; 556 Log.Clear; 521 557 //ReloadJobList; 522 558 end; … … 528 564 inherited; 529 565 end; 566 567 { TProgress } 530 568 531 569 procedure TProgress.SetMax(const AValue: Integer); … … 536 574 if FMax < 1 then FMax := 1; 537 575 if FValue >= FMax then FValue := FMax; 576 finally 577 FLock.Release; 578 end; 579 end; 580 581 procedure TProgress.SetText(AValue: string); 582 begin 583 try 584 FLock.Acquire; 585 if FText = AValue then Exit; 586 FText := AValue; 538 587 finally 539 588 FLock.Release; … … 563 612 end; 564 613 565 { TProgress }566 567 614 procedure TProgress.Increment; 568 615 begin 569 try570 FLock.Acquire;616 FLock.Acquire; 617 try 571 618 Value := Value + 1; 572 619 finally … … 577 624 procedure TProgress.Reset; 578 625 begin 579 try580 FLock.Acquire;626 FLock.Acquire; 627 try 581 628 FValue := 0; 582 629 finally … … 594 641 begin 595 642 FLock.Free; 596 inherited Destroy;643 inherited; 597 644 end; 598 645 … … 625 672 destructor TJob.Destroy; 626 673 begin 627 Progress.Free;674 FreeAndNil(Progress); 628 675 inherited; 629 676 end; -
trunk/Packages/Common/ULastOpenedList.pas
r10 r25 1 1 unit ULastOpenedList; 2 3 {$mode delphi}4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, Registry, URegistry, Menus, XMLConf ;6 Classes, SysUtils, Registry, URegistry, Menus, XMLConf, DOM; 9 7 10 8 type … … 30 28 procedure SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 31 29 procedure AddItem(FileName: string); 30 function GetFirstFileName: string; 32 31 published 33 32 property MaxCount: Integer read FMaxCount write SetMaxCount; … … 83 82 destructor TLastOpenedList.Destroy; 84 83 begin 85 Items.Free;84 FreeAndNil(Items); 86 85 inherited; 87 86 end; … … 93 92 begin 94 93 if Assigned(MenuItem) then begin 95 MenuItem.Clear; 94 while MenuItem.Count > Items.Count do 95 MenuItem.Delete(MenuItem.Count - 1); 96 while MenuItem.Count < Items.Count do begin 97 NewMenuItem := TMenuItem.Create(MenuItem); 98 MenuItem.Add(NewMenuItem); 99 end; 96 100 for I := 0 to Items.Count - 1 do begin 97 NewMenuItem := TMenuItem.Create(MenuItem); 98 NewMenuItem.Caption := Items[I]; 99 NewMenuItem.OnClick := ClickAction; 100 MenuItem.Add(NewMenuItem); 101 MenuItem.Items[I].Caption := Items[I]; 102 MenuItem.Items[I].OnClick := ClickAction; 101 103 end; 102 104 end; … … 139 141 OpenKey(Context.Key, True); 140 142 for I := 0 to Items.Count - 1 do 141 WriteString('File' + IntToStr(I), UTF8Decode(Items[I]));143 WriteString('File' + IntToStr(I), Items[I]); 142 144 finally 143 145 Free; … … 153 155 begin 154 156 with XMLConfig do begin 155 Count := GetValue( Path + '/Count', 0);157 Count := GetValue(DOMString(Path + '/Count'), 0); 156 158 if Count > MaxCount then Count := MaxCount; 157 159 Items.Clear; 158 160 for I := 0 to Count - 1 do begin 159 Value := GetValue(Path + '/File' + IntToStr(I), '');161 Value := string(GetValue(DOMString(Path + '/File' + IntToStr(I)), '')); 160 162 if Trim(Value) <> '' then Items.Add(Value); 161 163 end; … … 170 172 begin 171 173 with XMLConfig do begin 172 SetValue( Path + '/Count', Items.Count);174 SetValue(DOMString(Path + '/Count'), Items.Count); 173 175 for I := 0 to Items.Count - 1 do 174 SetValue( Path + '/File' + IntToStr(I), Items[I]);176 SetValue(DOMString(Path + '/File' + IntToStr(I)), DOMString(Items[I])); 175 177 Flush; 176 178 end; … … 185 187 end; 186 188 189 function TLastOpenedList.GetFirstFileName: string; 190 begin 191 if Items.Count > 0 then Result := Items[0] 192 else Result := ''; 193 end; 194 187 195 end. 188 196 -
trunk/Packages/Common/UListViewSort.pas
r15 r25 1 1 unit UListViewSort; 2 2 3 // Date: 2010-11-03 4 5 {$mode delphi} 3 // Date: 2019-05-17 6 4 7 5 interface 8 6 9 7 uses 10 {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,11 Controls, DateUtils, Dialogs, SpecializedList,Forms, Grids, StdCtrls, ExtCtrls,12 LclIntf, L Messages, LclType, LResources;8 {$IFDEF Windows}Windows, CommCtrl, LMessages, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils, 9 Controls, DateUtils, Dialogs, Forms, Grids, StdCtrls, ExtCtrls, 10 LclIntf, LclType, LResources, Generics.Collections, Generics.Defaults; 13 11 14 12 type … … 19 17 TCompareEvent = function (Item1, Item2: TObject): Integer of object; 20 18 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 19 20 TObjects = TObjectList<TObject>; 21 21 22 22 { TListViewSort } … … 52 52 {$ENDIF} 53 53 public 54 List: TListObject;55 Source: TListObject;54 Source: TObjects; 55 List: TObjects; 56 56 constructor Create(AOwner: TComponent); override; 57 57 destructor Destroy; override; … … 81 81 FOnChange: TNotifyEvent; 82 82 FStringGrid1: TStringGrid; 83 procedure DoOnChange; 83 84 procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 84 85 procedure GridDoOnResize(Sender: TObject); … … 90 91 function TextEnteredColumn(Index: Integer): Boolean; 91 92 function GetColValue(Index: Integer): string; 93 procedure Reset; 92 94 property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1; 93 95 published … … 98 100 end; 99 101 102 { TListViewEx } 103 104 TListViewEx = class(TWinControl) 105 private 106 FFilter: TListViewFilter; 107 FListView: TListView; 108 FListViewSort: TListViewSort; 109 procedure ResizeHanlder; 110 public 111 constructor Create(TheOwner: TComponent); override; 112 destructor Destroy; override; 113 published 114 property ListView: TListView read FListView write FListView; 115 property ListViewSort: TListViewSort read FListViewSort write FListViewSort; 116 property Filter: TListViewFilter read FFilter write FFilter; 117 property Visible; 118 end; 119 100 120 procedure Register; 101 121 … … 105 125 procedure Register; 106 126 begin 107 RegisterComponents('Common', [TListViewSort, TListViewFilter]); 127 RegisterComponents('Common', [TListViewSort, TListViewFilter, TListViewEx]); 128 end; 129 130 { TListViewEx } 131 132 procedure TListViewEx.ResizeHanlder; 133 begin 134 end; 135 136 constructor TListViewEx.Create(TheOwner: TComponent); 137 begin 138 inherited Create(TheOwner); 139 Filter := TListViewFilter.Create(Self); 140 Filter.Parent := Self; 141 Filter.Align := alBottom; 142 ListView := TListView.Create(Self); 143 ListView.Parent := Self; 144 ListView.Align := alClient; 145 ListViewSort := TListViewSort.Create(Self); 146 ListViewSort.ListView := ListView; 147 end; 148 149 destructor TListViewEx.Destroy; 150 begin 151 inherited; 108 152 end; 109 153 110 154 { TListViewFilter } 155 156 procedure TListViewFilter.DoOnChange; 157 begin 158 if Assigned(FOnChange) then FOnChange(Self); 159 end; 111 160 112 161 procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word; 113 162 Shift: TShiftState); 114 163 begin 115 if Assigned(FOnChange) then 116 FOnChange(Self); 164 DoOnChange; 117 165 end; 118 166 … … 142 190 var 143 191 I: Integer; 192 R: TRect; 144 193 begin 145 194 with FStringGrid1 do begin 146 Options := Options - [goEditing, goAlwaysShowEditor];147 //Columns.Clear;148 195 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 149 196 while Columns.Count < ListView.Columns.Count do Columns.Add; 150 197 for I := 0 to ListView.Columns.Count - 1 do begin 151 198 Columns[I].Width := ListView.Columns[I].Width; 199 if Selection.Left = I then begin 200 R := CellRect(I, 0); 201 Editor.Left := R.Left + 2; 202 Editor.Width := R.Width - 4; 203 end; 152 204 end; 153 Options := Options + [goEditing, goAlwaysShowEditor];154 205 end; 155 206 end; … … 182 233 Result := StringGrid.Cells[Index, 0] 183 234 else Result := ''; 235 end; 236 237 procedure TListViewFilter.Reset; 238 var 239 I: Integer; 240 begin 241 with StringGrid do 242 for I := 0 to ColCount - 1 do 243 Cells[I, 0] := ''; 244 DoOnChange; 184 245 end; 185 246 … … 274 335 end; 275 336 337 var 338 ListViewSortCompare: TCompareEvent; 339 340 function ListViewCompare(constref Item1, Item2: TObject): Integer; 341 begin 342 Result := ListViewSortCompare(Item1, Item2); 343 end; 344 276 345 procedure TListViewSort.Sort(Compare: TCompareEvent); 277 346 begin 347 // TODO: Because TFLGObjectList compare handler is not class method, 348 // it is necessary to use simple function compare handler with local variable 349 ListViewSortCompare := Compare; 278 350 if (List.Count > 0) then 279 List.Sort( Compare);351 List.Sort(TComparer<TObject>.Construct(ListViewCompare)); 280 352 end; 281 353 … … 283 355 begin 284 356 if Assigned(FOnFilter) then FOnFilter(Self) 285 else if Assigned(Source) then 286 List.Assign(Source) else 357 else if Assigned(Source) then begin 287 358 List.Clear; 359 List.AddRange(Source); 360 end else List.Clear; 288 361 if ListView.Items.Count <> List.Count then 289 362 ListView.Items.Count := List.Count; … … 340 413 begin 341 414 inherited; 342 List := T ListObject.Create;415 List := TObjects.Create; 343 416 List.OwnsObjects := False; 344 417 end; … … 346 419 destructor TListViewSort.Destroy; 347 420 begin 348 List.Free;421 FreeAndNil(List); 349 422 inherited; 350 423 end; … … 381 454 ItemLeft := Item.Left; 382 455 ItemLeft := 23; // Windows 7 workaround 383 456 384 457 Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias; 385 458 //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias)); … … 480 553 FHeaderHandle := ListView_GetHeader(FListView.Handle); 481 554 for I := 0 to FListView.Columns.Count - 1 do begin 555 {$push}{$warn 5057 off} 482 556 FillChar(Item, SizeOf(THDItem), 0); 557 {$pop} 483 558 Item.Mask := HDI_FORMAT; 484 559 Header_GetItem(FHeaderHandle, I, Item); -
trunk/Packages/Common/UMemory.pas
r15 r25 1 1 unit UMemory; 2 3 {$mode Delphi}{$H+}4 2 5 3 interface … … 44 42 end; 45 43 44 46 45 implementation 47 46 … … 50 49 procedure TPositionMemory.SetSize(AValue: Integer); 51 50 begin 52 inherited SetSize(AValue);51 inherited; 53 52 if FPosition > FSize then FPosition := FSize; 54 53 end; … … 107 106 begin 108 107 Size := 0; 109 inherited Destroy;108 inherited; 110 109 end; 111 110 112 111 procedure TMemory.WriteMemory(Position: Integer; Memory: TMemory); 113 112 begin 114 Move(Memory.FData, PByte( @FData+ Position)^, Memory.Size);113 Move(Memory.FData, PByte(PByte(@FData) + Position)^, Memory.Size); 115 114 end; 116 115 117 116 procedure TMemory.ReadMemory(Position: Integer; Memory: TMemory); 118 117 begin 119 Move(PByte( @FData+ Position)^, Memory.FData, Memory.Size);118 Move(PByte(PByte(@FData) + Position)^, Memory.FData, Memory.Size); 120 119 end; 121 120 -
trunk/Packages/Common/UPersistentForm.pas
r20 r25 1 1 unit UPersistentForm; 2 2 3 {$mode delphi} 4 5 // Date: 2015-04-18 3 // Date: 2020-11-26 6 4 7 5 interface 8 6 9 7 uses 10 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls; 8 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls, 9 ExtCtrls, LCLType; 11 10 12 11 type … … 25 24 FormRestoredSize: TRect; 26 25 FormWindowState: TWindowState; 26 FormFullScreen: Boolean; 27 27 Form: TForm; 28 28 procedure LoadFromRegistry(RegistryContext: TRegistryContext); … … 30 30 function CheckEntireVisible(Rect: TRect): TRect; 31 31 function CheckPartVisible(Rect: TRect; Part: Integer): TRect; 32 procedure Load(Form: TForm; DefaultMaximized: Boolean = False); 32 procedure Load(Form: TForm; DefaultMaximized: Boolean = False; 33 DefaultFullScreen: Boolean = False); 33 34 procedure Save(Form: TForm); 34 35 constructor Create(AOwner: TComponent); override; 36 procedure SetFullScreen(State: Boolean); 35 37 property RegistryContext: TRegistryContext read FRegistryContext 36 38 write FRegistryContext; … … 42 44 procedure Register; 43 45 46 44 47 implementation 45 46 48 47 49 procedure Register; … … 71 73 end; 72 74 75 if (Control is TPanel) then begin 76 with Form, TRegistryEx.Create do 77 try 78 RootKey := RegistryContext.RootKey; 79 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True); 80 if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin 81 if ValueExists('Width') then 82 TPanel(Control).Width := ReadInteger('Width'); 83 end; 84 if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin 85 if ValueExists('Height') then 86 TPanel(Control).Height := ReadInteger('Height'); 87 end; 88 finally 89 Free; 90 end; 91 end; 92 73 93 if Control is TWinControl then begin 74 94 WinControl := TWinControl(Control); … … 95 115 for I := 0 to TListView(Control).Columns.Count - 1 do begin 96 116 WriteInteger('ColWidth' + IntToStr(I), TListView(Control).Columns[I].Width); 117 end; 118 finally 119 Free; 120 end; 121 end; 122 123 if (Control is TPanel) then begin 124 with Form, TRegistryEx.Create do 125 try 126 RootKey := RegistryContext.RootKey; 127 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True); 128 if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin 129 WriteInteger('Width', TPanel(Control).Width); 130 end; 131 if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin 132 WriteInteger('Height', TPanel(Control).Height); 97 133 end; 98 134 finally … … 134 170 + FormRestoredSize.Top; 135 171 // Other state 136 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal))); 172 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState))); 173 FormFullScreen := ReadBoolWithDefault('FullScreen', FormFullScreen); 137 174 finally 138 175 Free; … … 158 195 // Other state 159 196 WriteInteger('WindowState', Integer(FormWindowState)); 197 WriteBool('FullScreen', FormFullScreen); 160 198 finally 161 199 Free; … … 215 253 end; 216 254 217 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False); 255 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False; 256 DefaultFullScreen: Boolean = False); 218 257 begin 219 258 Self.Form := Form; … … 223 262 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 224 263 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); 264 FormWindowState := Form.WindowState; 265 FormFullScreen := DefaultFullScreen; 225 266 226 267 LoadFromRegistry(RegistryContext); … … 242 283 Form.BoundsRect := FormNormalSize; 243 284 end; 285 if FormFullScreen then SetFullScreen(True); 244 286 LoadControl(Form); 245 287 end; … … 249 291 Self.Form := Form; 250 292 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 251 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 252 Form.RestoredHeight); 293 if not FormFullScreen then 294 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 295 Form.RestoredHeight); 253 296 FormWindowState := Form.WindowState; 254 297 SaveToRegistry(RegistryContext); … … 265 308 end; 266 309 310 procedure TPersistentForm.SetFullScreen(State: Boolean); 311 begin 312 if State then begin 313 FormFullScreen := True; 314 FormNormalSize := Form.BoundsRect; 315 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 316 Form.RestoredHeight); 317 FormWindowState := Form.WindowState; 318 ShowWindow(Form.Handle, SW_SHOWFULLSCREEN); 319 {$IFDEF WINDOWS} 320 Form.BorderStyle := bsNone; 321 {$ENDIF} 322 end else begin 323 FormFullScreen := False; 324 {$IFDEF WINDOWS} 325 Form.BorderStyle := bsSizeable; 326 {$ENDIF} 327 ShowWindow(Form.Handle, SW_SHOWNORMAL); 328 if FormWindowState = wsNormal then begin 329 Form.BoundsRect := FormNormalSize; 330 end else 331 if FormWindowState = wsMaximized then begin 332 Form.BoundsRect := FormRestoredSize; 333 Form.WindowState := wsMaximized; 334 end; 335 end; 336 end; 337 267 338 end. 268 339 -
trunk/Packages/Common/UPool.pas
r10 r25 1 1 unit UPool; 2 2 3 {$mode Delphi}{$H+}4 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, syncobjs, SpecializedList, UThreading;6 Classes, SysUtils, syncobjs, Generics.Collections, UThreading; 9 7 10 8 type … … 22 20 function NewItemObject: TObject; virtual; 23 21 public 24 Items: T ListObject;25 FreeItems: T ListObject;22 Items: TObjectList<TObject>; 23 FreeItems: TObjectList<TObject>; 26 24 function Acquire: TObject; virtual; 27 25 procedure Release(Item: TObject); virtual; … … 108 106 constructor TThreadedPool.Create; 109 107 begin 110 inherited Create;108 inherited; 111 109 Lock := TCriticalSection.Create; 112 110 end; … … 116 114 TotalCount := 0; 117 115 Lock.Free; 118 inherited Destroy;116 inherited; 119 117 end; 120 118 … … 185 183 begin 186 184 inherited; 187 Items := T ListObject.Create;188 FreeItems := T ListObject.Create;185 Items := TObjectList<TObject>.Create; 186 FreeItems := TObjectList<TObject>.Create; 189 187 FreeItems.OwnsObjects := False; 190 188 FReleaseEvent := TEvent.Create(nil, False, False, ''); -
trunk/Packages/Common/UPrefixMultiplier.pas
r10 r25 2 2 3 3 // Date: 2010-06-01 4 5 {$mode delphi}6 4 7 5 interface … … 21 19 { TPrefixMultiplier } 22 20 23 TPrefixMultiplier = class 21 TPrefixMultiplier = class(TComponent) 24 22 private 25 function TruncateDigits(Value: Double;Digits:Integer=3):Double;23 function TruncateDigits(Value: Double; Digits: Integer = 3): Double; 26 24 public 27 25 function Add(Value: Double; PrefixMultipliers: TPrefixMultiplierDef; … … 72 70 ); 73 71 72 procedure Register; 73 74 74 75 implementation 76 77 procedure Register; 78 begin 79 RegisterComponents('Common', [TPrefixMultiplier]); 80 end; 75 81 76 82 { TPrefixMultiplier } … … 92 98 end; 93 99 94 function TPrefixMultiplier.Add(Value: Double;PrefixMultipliers:TPrefixMultiplierDef95 ; UnitText:string;Digits:Integer):string;100 function TPrefixMultiplier.Add(Value: Double; PrefixMultipliers: TPrefixMultiplierDef 101 ; UnitText:string; Digits: Integer): string; 96 102 var 97 103 I: Integer; -
trunk/Packages/Common/URegistry.pas
r20 r25 1 1 unit URegistry; 2 3 {$MODE Delphi}4 2 5 3 interface … … 17 15 RootKey: HKEY; 18 16 Key: string; 17 class function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; static; overload; 18 class function Create(RootKey: HKEY; Key: string): TRegistryContext; static; overload; 19 19 class operator Equal(A, B: TRegistryContext): Boolean; 20 function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; overload;21 function Create(RootKey: HKEY; Key: string): TRegistryContext; overload;22 20 end; 23 21 … … 29 27 procedure SetCurrentContext(AValue: TRegistryContext); 30 28 public 29 function ReadChar(const Name: string): Char; 30 procedure WriteChar(const Name: string; Value: Char); 31 31 function ReadBoolWithDefault(const Name: string; 32 32 DefaultValue: Boolean): Boolean; 33 33 function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer; 34 34 function ReadStringWithDefault(const Name: string; DefaultValue: string): string; 35 function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char; 35 36 function ReadFloatWithDefault(const Name: string; 36 37 DefaultValue: Double): Double; … … 41 42 function GetValue(const Name: string; const DefaultValue: Boolean): Boolean; overload; 42 43 function GetValue(const Name: string; const DefaultValue: Double): Double; overload; 44 function GetValue(const Name: string; const DefaultValue: Char): Char; overload; 43 45 procedure SetValue(const Name: string; const Value: Integer); overload; 44 46 procedure SetValue(const Name: string; const Value: string); overload; 45 47 procedure SetValue(const Name: string; const Value: Boolean); overload; 46 48 procedure SetValue(const Name: string; const Value: Double); overload; 49 procedure SetValue(const Name: string; const Value: Char); overload; 47 50 property CurrentContext: TRegistryContext read GetCurrentContext write SetCurrentContext; 48 51 end; … … 53 56 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 54 57 58 55 59 implementation 56 60 57 58 61 { TRegistryContext } 59 62 … … 63 66 end; 64 67 65 function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext;68 class function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 66 69 begin 67 70 Result.RootKey := RegistryRootHKEY[RootKey]; … … 69 72 end; 70 73 71 function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext;74 class function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 72 75 begin 73 76 Result.RootKey := RootKey; … … 97 100 end; 98 101 102 function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char 103 ): Char; 104 begin 105 if ValueExists(Name) then Result := ReadChar(Name) 106 else begin 107 WriteChar(Name, DefaultValue); 108 Result := DefaultValue; 109 end; 110 end; 111 99 112 function TRegistryEx.ReadFloatWithDefault(const Name: string; 100 113 DefaultValue: Double): Double; … … 131 144 end; 132 145 146 function TRegistryEx.GetValue(const Name: string; const DefaultValue: Char 147 ): Char; 148 begin 149 Result := ReadCharWithDefault(Name, DefaultValue); 150 end; 151 133 152 procedure TRegistryEx.SetValue(const Name: string; const Value: Integer); 134 153 begin … … 149 168 begin 150 169 WriteFloat(Name, Value); 170 end; 171 172 procedure TRegistryEx.SetValue(const Name: string; const Value: Char); 173 begin 174 WriteChar(Name, Value); 151 175 end; 152 176 … … 171 195 function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean; 172 196 begin 173 {$IFDEF Linux}174 CloseKey;197 {$IFDEF UNIX} 198 //CloseKey; 175 199 {$ENDIF} 176 200 Result := inherited OpenKey(Key, CanCreate); … … 179 203 function TRegistryEx.GetCurrentContext: TRegistryContext; 180 204 begin 181 Result.Key := CurrentPath;205 Result.Key := String(CurrentPath); 182 206 Result.RootKey := RootKey; 183 207 end; … … 189 213 end; 190 214 215 function TRegistryEx.ReadChar(const Name: string): Char; 216 var 217 S: string; 218 begin 219 S := ReadString(Name); 220 if Length(S) > 0 then Result := S[1] 221 else Result := #0; 222 end; 223 224 procedure TRegistryEx.WriteChar(const Name: string; Value: Char); 225 begin 226 WriteString(Name, Value); 227 end; 228 191 229 function TRegistryEx.ReadBoolWithDefault(const Name: string; 192 230 DefaultValue: Boolean): Boolean; -
trunk/Packages/Common/UResetableThread.pas
r10 r25 1 1 unit UResetableThread; 2 3 {$mode Delphi}{$H+}4 2 5 3 interface … … 156 154 FThread.Name := 'ResetableThread'; 157 155 FThread.Parent := Self; 158 FThread. Resume;156 FThread.Start; 159 157 end; 160 158 … … 167 165 FreeAndNil(FStopEvent); 168 166 FreeAndNil(FLock); 169 inherited Destroy;167 inherited; 170 168 end; 171 169 … … 286 284 constructor TThreadPool.Create; 287 285 begin 288 inherited Create;286 inherited; 289 287 end; 290 288 … … 293 291 TotalCount := 0; 294 292 WaitForEmpty; 295 inherited Destroy;293 inherited; 296 294 end; 297 295 -
trunk/Packages/Common/UScaleDPI.pas
r15 r25 3 3 { See: http://wiki.lazarus.freepascal.org/High_DPI } 4 4 5 {$mode delphi}{$H+}6 7 5 interface 8 6 9 7 uses 10 Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, StdCtrls,11 Contnrs;8 Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, 9 Generics.Collections; 12 10 13 11 type 12 TControlDimensions = class; 14 13 15 14 { TControlDimension } … … 18 17 BoundsRect: TRect; 19 18 FontHeight: Integer; 20 Controls: T ObjectList; // TList<TControlDimension>19 Controls: TControlDimensions; 21 20 // Class specifics 22 21 ButtonSize: TPoint; // TToolBar … … 26 25 constructor Create; 27 26 destructor Destroy; override; 27 end; 28 29 TControlDimensions = class(TObjectList<TControlDimension>) 28 30 end; 29 31 … … 73 75 constructor TControlDimension.Create; 74 76 begin 75 Controls := T ObjectList.Create;77 Controls := TControlDimensions.Create; 76 78 end; 77 79 … … 79 81 begin 80 82 FreeAndNil(Controls); 81 inherited Destroy;83 inherited; 82 84 end; 83 85 … … 212 214 TempBmp: TBitmap; 213 215 Temp: array of TBitmap; 214 NewWidth, NewHeight: integer; 215 I: Integer; 216 begin 217 NewWidth := ScaleX(ImgList.Width, FromDPI.X); 218 NewHeight := ScaleY(ImgList.Height, FromDPI.Y); 219 220 SetLength(Temp, ImgList.Count); 221 for I := 0 to ImgList.Count - 1 do 222 begin 223 TempBmp := TBitmap.Create; 224 TempBmp.PixelFormat := pf32bit; 225 ImgList.GetBitmap(I, TempBmp); 226 Temp[I] := TBitmap.Create; 227 Temp[I].SetSize(NewWidth, NewHeight); 228 Temp[I].PixelFormat := pf32bit; 229 Temp[I].TransparentColor := TempBmp.TransparentColor; 230 //Temp[I].TransparentMode := TempBmp.TransparentMode; 231 Temp[I].Transparent := True; 232 Temp[I].Canvas.Brush.Style := bsSolid; 233 Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor; 234 Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height); 235 236 if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue; 237 Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp); 238 TempBmp.Free; 239 end; 240 241 ImgList.Clear; 242 ImgList.Width := NewWidth; 243 ImgList.Height := NewHeight; 244 245 for I := 0 to High(Temp) do 246 begin 247 ImgList.Add(Temp[I], nil); 248 Temp[i].Free; 216 NewWidth: Integer; 217 NewHeight: Integer; 218 I: Integer; 219 begin 220 ImgList.BeginUpdate; 221 try 222 NewWidth := ScaleX(ImgList.Width, FromDPI.X); 223 NewHeight := ScaleY(ImgList.Height, FromDPI.Y); 224 225 Temp := nil; 226 SetLength(Temp, ImgList.Count); 227 for I := 0 to ImgList.Count - 1 do 228 begin 229 TempBmp := TBitmap.Create; 230 try 231 TempBmp.PixelFormat := pf32bit; 232 ImgList.GetBitmap(I, TempBmp); 233 Temp[I] := TBitmap.Create; 234 Temp[I].SetSize(NewWidth, NewHeight); 235 {$IFDEF UNIX} 236 Temp[I].PixelFormat := pf24bit; 237 {$ELSE} 238 Temp[I].PixelFormat := pf32bit; 239 {$ENDIF} 240 Temp[I].TransparentColor := TempBmp.TransparentColor; 241 //Temp[I].TransparentMode := TempBmp.TransparentMode; 242 Temp[I].Transparent := True; 243 Temp[I].Canvas.Brush.Style := bsSolid; 244 Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor; 245 Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height); 246 247 if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue; 248 Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp); 249 finally 250 TempBmp.Free; 251 end; 252 end; 253 254 ImgList.Clear; 255 ImgList.Width := NewWidth; 256 ImgList.Height := NewHeight; 257 258 for I := 0 to High(Temp) do 259 begin 260 ImgList.Add(Temp[I], nil); 261 Temp[i].Free; 262 end; 263 finally 264 ImgList.EndUpdate; 249 265 end; 250 266 end; … … 284 300 WinControl: TWinControl; 285 301 ToolBarControl: TToolBar; 286 OldAnchors: TAnchors; 287 OldAutoSize: Boolean; 288 begin 302 //OldAnchors: TAnchors; 303 //OldAutoSize: Boolean; 304 begin 305 //if not (Control is TCustomPage) then 306 // Resize childs first 307 if Control is TWinControl then begin 308 WinControl := TWinControl(Control); 309 if WinControl.ControlCount > 0 then begin 310 for I := 0 to WinControl.ControlCount - 1 do begin 311 if WinControl.Controls[I] is TControl then begin 312 ScaleControl(WinControl.Controls[I], FromDPI); 313 end; 314 end; 315 end; 316 end; 317 289 318 //if Control is TMemo then Exit; 290 319 //if Control is TForm then … … 312 341 with TCoolBar(Control) do begin 313 342 BeginUpdate; 314 for I := 0 to Bands.Count - 1 do 315 with Bands[I] do begin 316 MinWidth := ScaleX(MinWidth, FromDPI.X); 317 MinHeight := ScaleY(MinHeight, FromDPI.Y); 318 Width := ScaleX(Width, FromDPI.X); 319 //Control.Invalidate; 343 try 344 for I := 0 to Bands.Count - 1 do 345 with Bands[I] do begin 346 MinWidth := ScaleX(MinWidth, FromDPI.X); 347 MinHeight := ScaleY(MinHeight, FromDPI.Y); 348 // Workaround to bad band width auto sizing 349 //Width := ScaleX(Width, FromDPI.X); 350 Width := ScaleX(Control.Width + 28, FromDPI.X); 351 //Control.Invalidate; 352 end; 353 // Workaround for bad autosizing of coolbar 354 if AutoSize then begin 355 AutoSize := False; 356 Height := ScaleY(Height, FromDPI.Y); 357 AutoSize := True; 320 358 end; 321 EndUpdate; 359 finally 360 EndUpdate; 361 end; 322 362 end; 323 363 … … 330 370 end; 331 371 332 //if not (Control is TCustomPage) then333 if Control is TWinControl then begin334 WinControl := TWinControl(Control);335 if WinControl.ControlCount > 0 then begin336 for I := 0 to WinControl.ControlCount - 1 do begin337 if WinControl.Controls[I] is TControl then begin338 ScaleControl(WinControl.Controls[I], FromDPI);339 end;340 end;341 end;342 end;343 372 //if Control is TForm then 344 373 // Control.EnableAutoSizing; -
trunk/Packages/Common/USyncCounter.pas
r10 r25 1 1 unit USyncCounter; 2 3 {$mode delphi}4 2 5 3 interface … … 25 23 procedure Assign(Source: TSyncCounter); 26 24 end; 25 27 26 28 27 implementation … … 69 68 begin 70 69 Lock.Free; 71 inherited Destroy;70 inherited; 72 71 end; 73 72 -
trunk/Packages/Common/UTheme.pas
r16 r25 5 5 uses 6 6 Classes, SysUtils, Graphics, ComCtrls, Controls, ExtCtrls, Menus, StdCtrls, 7 Spin, Forms, Contnrs, Grids;7 Spin, Forms, Generics.Collections, Grids; 8 8 9 9 type … … 19 19 { TThemes } 20 20 21 TThemes = class(TObjectList )21 TThemes = class(TObjectList<TTheme>) 22 22 function AddNew(Name: string): TTheme; 23 23 function FindByName(Name: string): TTheme; … … 42 42 end; 43 43 44 const 45 ThemeNameSystem = 'System'; 46 ThemeNameLight = 'Light'; 47 ThemeNameDark = 'Dark'; 48 44 49 procedure Register; 50 45 51 46 52 implementation … … 74 80 procedure TThemes.LoadToStrings(Strings: TStrings); 75 81 var 76 Theme: TTheme;82 I: Integer; 77 83 begin 78 Strings.Clear; 79 for Theme in Self do 80 Strings.AddObject(Theme.Name, Theme); 84 Strings.BeginUpdate; 85 try 86 while Strings.Count < Count do Strings.Add(''); 87 while Strings.Count > Count do Strings.Delete(Strings.Count - 1); 88 for I := 0 to Count - 1 do begin 89 Strings[I] := Items[I].Name; 90 Strings.Objects[I] := Items[I]; 91 end; 92 finally 93 Strings.EndUpdate; 94 end; 81 95 end; 82 96 … … 97 111 inherited; 98 112 Themes := TThemes.Create; 99 with Themes.AddNew( 'System') do begin113 with Themes.AddNew(ThemeNameSystem) do begin 100 114 ColorWindow := clWindow; 101 115 ColorWindowText := clWindowText; … … 105 119 end; 106 120 Theme := TTheme(Themes.First); 107 with Themes.AddNew( 'Dark') do begin121 with Themes.AddNew(ThemeNameDark) do begin 108 122 ColorWindow := RGBToColor($20, $20, $20); 109 123 ColorWindowText := clWhite; … … 112 126 ColorControlSelected := RGBToColor(96, 125, 155); 113 127 end; 114 with Themes.AddNew( 'Light') do begin128 with Themes.AddNew(ThemeNameLight) do begin 115 129 ColorWindow := clWhite; 116 130 ColorWindowText := clBlack; … … 123 137 destructor TThemeManager.Destroy; 124 138 begin 125 Themes.Free;126 inherited Destroy;139 FreeAndNil(Themes); 140 inherited; 127 141 end; 128 142 … … 132 146 I: Integer; 133 147 begin 134 for I := 0 to Component.ComponentCount - 1 do 135 ApplyTheme(Component.Components[I]); 148 if Component is TWinControl then begin 149 for I := 0 to TWinControl(Component).ControlCount - 1 do 150 ApplyTheme(TWinControl(Component).Controls[I]); 151 end; 136 152 137 153 if Component is TControl then begin … … 139 155 if (Control is TEdit) or (Control is TSpinEdit) or (Control is TComboBox) and 140 156 (Control is TMemo) or (Control is TListView) or (Control is TCustomDrawGrid) or 141 (Control is TCheckBox) then begin157 (Control is TCheckBox) or (Control is TPageControl) or (Control is TRadioButton) then begin 142 158 Control.Color := FTheme.ColorWindow; 143 159 Control.Font.Color := FTheme.ColorWindowText; … … 151 167 (Control as TCustomDrawGrid).Editor.Font.Color := FTheme.ColorWindowText; 152 168 end; 169 170 if Control is TPageControl then begin 171 for I := 0 to TPageControl(Component).PageCount - 1 do 172 ApplyTheme(TPageControl(Component).Pages[I]); 173 end; 174 175 if Control is TCoolBar then begin 176 (Control as TCoolBar).Themed := False; 177 end; 153 178 end; 154 179 end; … … 156 181 procedure TThemeManager.UseTheme(Form: TForm); 157 182 begin 158 if not Used and (FTheme.Name = 'System') then Exit;183 if not Used and (FTheme.Name = ThemeNameSystem) then Exit; 159 184 ApplyTheme(Form); 160 185 Used := True; -
trunk/Packages/Common/UThreading.pas
r10 r25 1 1 unit UThreading; 2 2 3 {$mode delphi}4 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, Forms, Contnrs, SyncObjs;6 Classes, SysUtils, Forms, Generics.Collections, SyncObjs; 9 7 10 8 type 11 9 TExceptionEvent = procedure (Sender: TObject; E: Exception) of object; 12 10 TMethodCall = procedure of object; 13 14 11 15 12 { TVirtualThread } … … 22 19 function GetSuspended: Boolean; virtual; abstract; 23 20 function GetTerminated: Boolean; virtual; abstract; 24 function GetThreadId: Integer; virtual; abstract;21 function GetThreadId: TThreadID; virtual; abstract; 25 22 procedure SetFreeOnTerminate(const AValue: Boolean); virtual; abstract; 26 23 procedure SetPriority(const AValue: TThreadPriority); virtual; abstract; … … 30 27 Name: string; 31 28 procedure Execute; virtual; abstract; 32 procedure Resume; virtual; abstract;33 procedure Suspend; virtual; abstract;34 29 procedure Start; virtual; abstract; 35 30 procedure Terminate; virtual; abstract; … … 44 39 property Terminated: Boolean read GetTerminated write SetTerminated; 45 40 property Finished: Boolean read GetFinished; 46 property ThreadId: Integerread GetThreadId;41 property ThreadId: TThreadID read GetThreadId; 47 42 end; 48 43 … … 70 65 function GetSuspended: Boolean; override; 71 66 function GetTerminated: Boolean; override; 72 function GetThreadId: Integer; override;67 function GetThreadId: TThreadID; override; 73 68 procedure SetFreeOnTerminate(const AValue: Boolean); override; 74 69 procedure SetPriority(const AValue: TThreadPriority); override; … … 81 76 procedure Sleep(Delay: Integer); override; 82 77 procedure Execute; override; 83 procedure Resume; override;84 procedure Suspend; override;85 78 procedure Start; override; 86 79 procedure Terminate; override; … … 106 99 { TThreadList } 107 100 108 TThreadList = class(TObjectList )109 function FindById(Id: Integer): TVirtualThread;101 TThreadList = class(TObjectList<TVirtualThread>) 102 function FindById(Id: TThreadID): TVirtualThread; 110 103 constructor Create; virtual; 111 104 end; … … 134 127 Thread.FreeOnTerminate := False; 135 128 Thread.Method := Method; 136 Thread. Resume;129 Thread.Start; 137 130 while (Thread.State = ttsRunning) or (Thread.State = ttsReady) do begin 138 131 if MainThreadID = ThreadID then Application.ProcessMessages; … … 155 148 Thread.Method := Method; 156 149 Thread.OnFinished := CallBack; 157 Thread. Resume;150 Thread.Start; 158 151 //if Thread.State = ttsExceptionOccured then 159 152 // raise Exception.Create(Thread.ExceptionMessage); … … 168 161 if MainThreadID = ThreadID then Method 169 162 else begin 170 Thread := ThreadList.FindById(ThreadID); 163 try 164 ThreadListLock.Acquire; 165 Thread := ThreadList.FindById(ThreadID); 166 finally 167 ThreadListLock.Release; 168 end; 171 169 if Assigned(Thread) then begin 172 170 Thread.Synchronize(Method); … … 177 175 { TThreadList } 178 176 179 function TThreadList.FindById(Id: Integer): TVirtualThread;177 function TThreadList.FindById(Id: TThreadID): TVirtualThread; 180 178 var 181 179 I: Integer; 182 180 begin 183 181 I := 0; 184 while (I < ThreadList.Count) and (T VirtualThread(ThreadList[I]).ThreadID <> Id) do182 while (I < ThreadList.Count) and (ThreadList[I].ThreadID <> Id) do 185 183 Inc(I); 186 if I < ThreadList.Count then Result := T VirtualThread(ThreadList[I])184 if I < ThreadList.Count then Result := ThreadList[I] 187 185 else Result := nil; 188 186 end; … … 237 235 end; 238 236 239 function TListedThread.GetThreadId: Integer;237 function TListedThread.GetThreadId: TThreadID; 240 238 begin 241 239 Result := FThread.ThreadID; … … 294 292 end; 295 293 FThread.Free; 296 inherited Destroy;294 inherited; 297 295 end; 298 296 … … 313 311 procedure TListedThread.Execute; 314 312 begin 315 end;316 317 procedure TListedThread.Resume;318 begin319 FThread.Resume;320 end;321 322 procedure TListedThread.Suspend;323 begin324 FThread.Suspend;325 313 end; 326 314 -
trunk/Packages/Common/UURI.pas
r10 r25 2 2 3 3 // Date: 2011-04-04 4 5 {$mode delphi}6 4 7 5 interface … … 85 83 end; 86 84 85 87 86 implementation 88 87 89 88 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 90 89 var 91 I , J: Integer;90 I: Integer; 92 91 Matched: Boolean; 93 92 begin … … 113 112 function RightCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 114 113 var 115 I , J: Integer;114 I: Integer; 116 115 Matched: Boolean; 117 116 begin … … 183 182 begin 184 183 Items.Free; 185 inherited Destroy;184 inherited; 186 185 end; 187 186 … … 202 201 203 202 procedure TURI.SetAsString(Value: string); 204 var205 HostAddr: string;206 HostPort: string;207 203 begin 208 204 LeftCutString(Value, Scheme, ':'); … … 235 231 begin 236 232 Path.Free; 237 inherited Destroy;233 inherited; 238 234 end; 239 235 … … 246 242 Fragment := TURI(Source).Fragment; 247 243 Query := TURI(Source).Query; 248 end else inherited Assign(Source);244 end else inherited; 249 245 end; 250 246 … … 294 290 destructor TURL.Destroy; 295 291 begin 296 inherited Destroy;292 inherited; 297 293 end; 298 294 … … 347 343 begin 348 344 Directory.Free; 349 inherited Destroy; 350 end; 351 345 inherited; 346 end; 352 347 353 348 end. -
trunk/Packages/Common/UXMLUtils.pas
r15 r25 1 1 unit UXMLUtils; 2 3 {$mode delphi}4 2 5 3 interface … … 7 5 uses 8 6 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils, XMLRead, XMLWrite, DOM;7 Classes, SysUtils, DateUtils, DOM, xmlread; 10 8 11 9 function XMLTimeToDateTime(XMLDateTime: string): TDateTime; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;10 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 13 11 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 14 12 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); … … 21 19 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 20 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 21 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 23 22 24 23 25 24 implementation 25 26 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 27 var 28 Parser: TDOMParser; 29 Src: TXMLInputSource; 30 InFile: TFileStream; 31 begin 32 try 33 InFile := TFileStream.Create(FileName, fmOpenRead); 34 Src := TXMLInputSource.Create(InFile); 35 Parser := TDOMParser.Create; 36 Parser.Options.PreserveWhitespace := True; 37 Parser.Parse(Src, Doc); 38 finally 39 Src.Free; 40 Parser.Free; 41 InFile.Free; 42 end; 43 end; 26 44 27 45 function GetTimeZoneBias: Integer; … … 30 48 TimeZoneInfo: TTimeZoneInformation; 31 49 begin 50 {$push}{$warn 5057 off} 32 51 case GetTimeZoneInformation(TimeZoneInfo) of 33 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;34 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;52 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 53 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 35 54 else 36 55 Result := 0; 37 56 end; 57 {$pop} 38 58 end; 39 59 {$ELSE} … … 45 65 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 46 66 var 47 I , J: Integer;67 I: Integer; 48 68 Matched: Boolean; 49 69 begin … … 99 119 if Pos('Z', XMLDateTime) > 0 then 100 120 LeftCutString(XMLDateTime, Part, 'Z'); 101 SecondFraction := StrToFloat('0' + De cimalSeparator + Part);121 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 102 122 Millisecond := Trunc(SecondFraction * 1000); 103 123 end else begin … … 118 138 end; 119 139 120 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;140 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 121 141 const 122 142 Neg: array[Boolean] of string = ('+', '-'); … … 139 159 NewNode: TDOMNode; 140 160 begin 141 NewNode := Node.OwnerDocument.CreateElement( Name);142 NewNode.TextContent := IntToStr(Value);161 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 162 NewNode.TextContent := DOMString(IntToStr(Value)); 143 163 Node.AppendChild(NewNode); 144 164 end; … … 148 168 NewNode: TDOMNode; 149 169 begin 150 NewNode := Node.OwnerDocument.CreateElement( Name);151 NewNode.TextContent := IntToStr(Value);170 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 171 NewNode.TextContent := DOMString(IntToStr(Value)); 152 172 Node.AppendChild(NewNode); 153 173 end; … … 157 177 NewNode: TDOMNode; 158 178 begin 159 NewNode := Node.OwnerDocument.CreateElement( Name);160 NewNode.TextContent := BoolToStr(Value);179 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 180 NewNode.TextContent := DOMString(BoolToStr(Value)); 161 181 Node.AppendChild(NewNode); 162 182 end; … … 166 186 NewNode: TDOMNode; 167 187 begin 168 NewNode := Node.OwnerDocument.CreateElement( Name);169 NewNode.TextContent := Value;188 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 189 NewNode.TextContent := DOMString(Value); 170 190 Node.AppendChild(NewNode); 171 191 end; … … 175 195 NewNode: TDOMNode; 176 196 begin 177 NewNode := Node.OwnerDocument.CreateElement( Name);178 NewNode.TextContent := D ateTimeToXMLTime(Value);197 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 198 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 179 199 Node.AppendChild(NewNode); 180 200 end; … … 185 205 begin 186 206 Result := DefaultValue; 187 NewNode := Node.FindNode( Name);188 if Assigned(NewNode) then 189 Result := StrToInt( NewNode.TextContent);207 NewNode := Node.FindNode(DOMString(Name)); 208 if Assigned(NewNode) then 209 Result := StrToInt(string(NewNode.TextContent)); 190 210 end; 191 211 … … 195 215 begin 196 216 Result := DefaultValue; 197 NewNode := Node.FindNode( Name);198 if Assigned(NewNode) then 199 Result := StrToInt64( NewNode.TextContent);217 NewNode := Node.FindNode(DOMString(Name)); 218 if Assigned(NewNode) then 219 Result := StrToInt64(string(NewNode.TextContent)); 200 220 end; 201 221 … … 205 225 begin 206 226 Result := DefaultValue; 207 NewNode := Node.FindNode( Name);208 if Assigned(NewNode) then 209 Result := StrToBool( NewNode.TextContent);227 NewNode := Node.FindNode(DOMString(Name)); 228 if Assigned(NewNode) then 229 Result := StrToBool(string(NewNode.TextContent)); 210 230 end; 211 231 … … 215 235 begin 216 236 Result := DefaultValue; 217 NewNode := Node.FindNode( Name);218 if Assigned(NewNode) then 219 Result := NewNode.TextContent;237 NewNode := Node.FindNode(DOMString(Name)); 238 if Assigned(NewNode) then 239 Result := string(NewNode.TextContent); 220 240 end; 221 241 … … 226 246 begin 227 247 Result := DefaultValue; 228 NewNode := Node.FindNode( Name);229 if Assigned(NewNode) then 230 Result := XMLTimeToDateTime( NewNode.TextContent);248 NewNode := Node.FindNode(DOMString(Name)); 249 if Assigned(NewNode) then 250 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 231 251 end; 232 252
Note:
See TracChangeset
for help on using the changeset viewer.