Changeset 75 for trunk/Packages/Common
- Timestamp:
- Jun 4, 2024, 12:22:49 AM (6 months ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 49 added
- 6 deleted
- 2 edited
- 1 copied
- 22 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/ApplicationInfo.pas
r74 r75 1 unit UApplicationInfo; 2 3 {$mode delphi} 1 unit ApplicationInfo; 4 2 5 3 interface 6 4 7 5 uses 8 SysUtils, Registry, Classes, Forms, URegistry;6 SysUtils, Classes, Forms, RegistryEx, Controls, Graphics, LCLType; 9 7 10 8 type … … 14 12 TApplicationInfo = class(TComponent) 15 13 private 14 FDescription: TTranslateString; 15 FIcon: TBitmap; 16 16 FIdentification: Byte; 17 FLicense: string; 17 18 FVersionMajor: Byte; 18 19 FVersionMinor: Byte; … … 31 32 public 32 33 constructor Create(AOwner: TComponent); override; 34 destructor Destroy; override; 33 35 property Version: string read GetVersion; 36 function GetRegistryContext: TRegistryContext; 34 37 published 35 38 property Identification: Byte read FIdentification write FIdentification; … … 44 47 property EmailContact: string read FEmailContact write FEmailContact; 45 48 property AppName: string read FAppName write FAppName; 49 property Description: TTranslateString read FDescription write FDescription; 46 50 property ReleaseDate: TDateTime read FReleaseDate write FReleaseDate; 47 51 property RegistryKey: string read FRegistryKey write FRegistryKey; 48 52 property RegistryRoot: TRegistryRoot read FRegistryRoot write FRegistryRoot; 53 property License: string read FLicense write FLicense; 54 property Icon: TBitmap read FIcon write FIcon; 49 55 end; 50 56 51 57 procedure Register; 52 58 59 53 60 implementation 54 61 55 62 procedure Register; 56 63 begin … … 69 76 constructor TApplicationInfo.Create(AOwner: TComponent); 70 77 begin 71 inherited Create(AOwner);78 inherited; 72 79 FVersionMajor := 1; 73 80 FIdentification := 1; … … 75 82 FRegistryKey := '\Software\' + FAppName; 76 83 FRegistryRoot := rrKeyCurrentUser; 84 FIcon := TBitmap.Create; 85 end; 86 87 destructor TApplicationInfo.Destroy; 88 begin 89 FreeAndNil(FIcon); 90 inherited; 91 end; 92 93 function TApplicationInfo.GetRegistryContext: TRegistryContext; 94 begin 95 Result := TRegistryContext.Create(RegistryRoot, RegistryKey); 77 96 end; 78 97 -
trunk/Packages/Common/Common.Delay.pas
r74 r75 1 unit UDelay; 2 3 {$mode delphi} 1 unit Common.Delay; 4 2 5 3 interface … … 73 71 74 72 end. 75 -
trunk/Packages/Common/Common.lpk
r74 r75 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"/> 6 <Type Value="RunAndDesignTime"/> 6 7 <AddToProjectUsesSection Value="True"/> 7 8 <Author Value="Chronos (robie@centrum.cz)"/> … … 10 11 <PathDelim Value="\"/> 11 12 <SearchPaths> 12 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 13 <OtherUnitFiles Value="Forms"/> 14 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(BuildMode)"/> 13 15 </SearchPaths> 16 <Parsing> 17 <SyntaxOptions> 18 <SyntaxMode Value="Delphi"/> 19 <CStyleOperator Value="False"/> 20 <AllowLabel Value="False"/> 21 <CPPInline Value="False"/> 22 </SyntaxOptions> 23 </Parsing> 24 <CodeGeneration> 25 <Optimizations> 26 <OptimizationLevel Value="0"/> 27 </Optimizations> 28 </CodeGeneration> 29 <Linking> 30 <Debugging> 31 <GenerateDebugInfo Value="False"/> 32 </Debugging> 33 </Linking> 14 34 <Other> 15 35 <CompilerMessages> 16 < UseMsgFile Value="True"/>36 <IgnoredMessages idx6058="True" idx5071="True" idx5024="True" idx3124="True" idx3123="True"/> 17 37 </CompilerMessages> 18 <CompilerPath Value="$(CompPath)"/>19 38 </Other> 20 39 </CompilerOptions> 21 <Description Value="Various libraries"/> 22 <License Value="GNU/GPL"/> 23 <Version Minor="7"/> 24 <Files Count="19"> 40 <Description Value="Common package with various useful units. 41 42 Source: https://svn.zdechov.net/PascalClassLibrary/Common/"/> 43 <License Value="Copy left."/> 44 <Version Minor="12"/> 45 <Files Count="36"> 25 46 <Item1> 26 47 <Filename Value="StopWatch.pas"/> … … 28 49 </Item1> 29 50 <Item2> 30 <Filename Value=" UCommon.pas"/>31 <UnitName Value=" UCommon"/>51 <Filename Value="Common.pas"/> 52 <UnitName Value="Common"/> 32 53 </Item2> 33 54 <Item3> 34 <Filename Value=" UDebugLog.pas"/>35 <HasRegisterProc Value="True"/> 36 <UnitName Value=" UDebugLog"/>55 <Filename Value="DebugLog.pas"/> 56 <HasRegisterProc Value="True"/> 57 <UnitName Value="DebugLog"/> 37 58 </Item3> 38 59 <Item4> 39 <Filename Value=" UDelay.pas"/>40 <UnitName Value=" UDelay"/>60 <Filename Value="Common.Delay.pas"/> 61 <UnitName Value="Common.Delay"/> 41 62 </Item4> 42 63 <Item5> 43 <Filename Value="UPrefixMultiplier.pas"/> 44 <UnitName Value="UPrefixMultiplier"/> 64 <Filename Value="PrefixMultiplier.pas"/> 65 <HasRegisterProc Value="True"/> 66 <UnitName Value="PrefixMultiplier"/> 45 67 </Item5> 46 68 <Item6> 47 <Filename Value="U URI.pas"/>48 <UnitName Value="U URI"/>69 <Filename Value="URI.pas"/> 70 <UnitName Value="URI"/> 49 71 </Item6> 50 72 <Item7> 51 <Filename Value=" UThreading.pas"/>52 <UnitName Value=" UThreading"/>73 <Filename Value="Threading.pas"/> 74 <UnitName Value="Threading"/> 53 75 </Item7> 54 76 <Item8> 55 <Filename Value=" UMemory.pas"/>56 <UnitName Value=" UMemory"/>77 <Filename Value="Memory.pas"/> 78 <UnitName Value="Memory"/> 57 79 </Item8> 58 80 <Item9> 59 <Filename Value=" UResetableThread.pas"/>60 <UnitName Value=" UResetableThread"/>81 <Filename Value="ResetableThread.pas"/> 82 <UnitName Value="ResetableThread"/> 61 83 </Item9> 62 84 <Item10> 63 <Filename Value=" UPool.pas"/>64 <UnitName Value=" UPool"/>85 <Filename Value="Pool.pas"/> 86 <UnitName Value="Pool"/> 65 87 </Item10> 66 88 <Item11> 67 <Filename Value=" ULastOpenedList.pas"/>68 <HasRegisterProc Value="True"/> 69 <UnitName Value=" ULastOpenedList"/>89 <Filename Value="LastOpenedList.pas"/> 90 <HasRegisterProc Value="True"/> 91 <UnitName Value="LastOpenedList"/> 70 92 </Item11> 71 93 <Item12> 72 <Filename Value=" URegistry.pas"/>73 <UnitName Value=" URegistry"/>94 <Filename Value="RegistryEx.pas"/> 95 <UnitName Value="RegistryEx"/> 74 96 </Item12> 75 97 <Item13> 76 <Filename Value=" UJobProgressView.pas"/>77 <HasRegisterProc Value="True"/> 78 <UnitName Value=" UJobProgressView"/>98 <Filename Value="JobProgressView.pas"/> 99 <HasRegisterProc Value="True"/> 100 <UnitName Value="JobProgressView"/> 79 101 </Item13> 80 102 <Item14> 81 <Filename Value=" UXMLUtils.pas"/>82 <UnitName Value=" UXMLUtils"/>103 <Filename Value="XML.pas"/> 104 <UnitName Value="XML"/> 83 105 </Item14> 84 106 <Item15> 85 <Filename Value=" UApplicationInfo.pas"/>86 <HasRegisterProc Value="True"/> 87 <UnitName Value=" UApplicationInfo"/>107 <Filename Value="ApplicationInfo.pas"/> 108 <HasRegisterProc Value="True"/> 109 <UnitName Value="ApplicationInfo"/> 88 110 </Item15> 89 111 <Item16> 90 <Filename Value=" USyncCounter.pas"/>91 <UnitName Value=" USyncCounter"/>112 <Filename Value="SyncCounter.pas"/> 113 <UnitName Value="SyncCounter"/> 92 114 </Item16> 93 115 <Item17> 94 <Filename Value=" UListViewSort.pas"/>95 <HasRegisterProc Value="True"/> 96 <UnitName Value=" UListViewSort"/>116 <Filename Value="ListViewSort.pas"/> 117 <HasRegisterProc Value="True"/> 118 <UnitName Value="ListViewSort"/> 97 119 </Item17> 98 120 <Item18> 99 <Filename Value=" UPersistentForm.pas"/>100 <HasRegisterProc Value="True"/> 101 <UnitName Value=" UPersistentForm"/>121 <Filename Value="PersistentForm.pas"/> 122 <HasRegisterProc Value="True"/> 123 <UnitName Value="PersistentForm"/> 102 124 </Item18> 103 125 <Item19> 104 <Filename Value=" UFindFile.pas"/>105 <HasRegisterProc Value="True"/> 106 <UnitName Value=" UFindFile"/>126 <Filename Value="FindFile.pas"/> 127 <HasRegisterProc Value="True"/> 128 <UnitName Value="FindFile"/> 107 129 </Item19> 130 <Item20> 131 <Filename Value="ScaleDPI.pas"/> 132 <HasRegisterProc Value="True"/> 133 <UnitName Value="ScaleDPI"/> 134 </Item20> 135 <Item21> 136 <Filename Value="Theme.pas"/> 137 <HasRegisterProc Value="True"/> 138 <UnitName Value="Theme"/> 139 </Item21> 140 <Item22> 141 <Filename Value="StringTable.pas"/> 142 <UnitName Value="StringTable"/> 143 </Item22> 144 <Item23> 145 <Filename Value="MetaCanvas.pas"/> 146 <UnitName Value="MetaCanvas"/> 147 </Item23> 148 <Item24> 149 <Filename Value="Geometric.pas"/> 150 <UnitName Value="Geometric"/> 151 </Item24> 152 <Item25> 153 <Filename Value="Translator.pas"/> 154 <HasRegisterProc Value="True"/> 155 <UnitName Value="Translator"/> 156 </Item25> 157 <Item26> 158 <Filename Value="Languages.pas"/> 159 <UnitName Value="Languages"/> 160 </Item26> 161 <Item27> 162 <Filename Value="PixelPointer.pas"/> 163 <UnitName Value="PixelPointer"/> 164 </Item27> 165 <Item28> 166 <Filename Value="DataFile.pas"/> 167 <UnitName Value="DataFile"/> 168 </Item28> 169 <Item29> 170 <Filename Value="TestCase.pas"/> 171 <UnitName Value="TestCase"/> 172 </Item29> 173 <Item30> 174 <Filename Value="Generics.pas"/> 175 <UnitName Value="Generics"/> 176 </Item30> 177 <Item31> 178 <Filename Value="CommonPackage.pas"/> 179 <Type Value="Main Unit"/> 180 <UnitName Value="CommonPackage"/> 181 </Item31> 182 <Item32> 183 <Filename Value="Table.pas"/> 184 <UnitName Value="Table"/> 185 </Item32> 186 <Item33> 187 <Filename Value="FormEx.pas"/> 188 <HasRegisterProc Value="True"/> 189 <UnitName Value="FormEx"/> 190 </Item33> 191 <Item34> 192 <Filename Value="Forms\FormTests.pas"/> 193 <UnitName Value="FormTests"/> 194 </Item34> 195 <Item35> 196 <Filename Value="Forms\FormTest.pas"/> 197 <UnitName Value="FormTest"/> 198 </Item35> 199 <Item36> 200 <Filename Value="Forms\FormAbout.pas"/> 201 <UnitName Value="FormAbout"/> 202 </Item36> 108 203 </Files> 204 <CompatibilityMode Value="True"/> 109 205 <i18n> 110 206 <EnableI18N Value="True"/> 111 207 <OutDir Value="Languages"/> 208 <EnableI18NForLFM Value="True"/> 112 209 </i18n> 113 <Type Value="RunAndDesignTime"/>114 210 <RequiredPkgs Count="2"> 115 211 <Item1> 116 <PackageName Value=" TemplateGenerics"/>212 <PackageName Value="LCL"/> 117 213 </Item1> 118 214 <Item2> -
trunk/Packages/Common/Common.pas
r74 r75 1 unit UCommon; 2 3 {$mode delphi} 1 unit Common; 4 2 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: string; List: TList<string>): string; 68 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 69 function LastPos(const SubStr: String; const S: String): Integer; 70 function LoadFileToStr(const FileName: TFileName): AnsiString; 71 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 72 function MergeArray(A, B: array of string): TStringArray; 73 function OccurenceOfChar(What: Char; Where: string): Integer; 74 procedure OpenWebPage(URL: string); 75 procedure OpenEmail(Email: string); 76 procedure OpenFileInShell(FileName: string); 77 function PosFromIndex(SubStr: string; Text: string; 78 StartIndex: Integer): Integer; 79 function PosFromIndexReverse(SubStr: string; Text: string; 80 StartIndex: Integer): Integer; 81 function RemoveQuotes(Text: string): string; 82 procedure SaveStringToFile(S, FileName: string); 53 83 procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean); overload; 54 84 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload; 55 85 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload; 56 86 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(CommandLine: 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; 87 procedure SearchFiles(AList: TStrings; Dir: string; 88 FilterMethod: TFilterMethod = nil; FileNameMethod: TFileNameMethod = nil); 89 function SplitString(var Text: string; Count: Word): string; 90 function StripTags(const S: string): string; 91 function TryHexToInt(Data: string; out Value: Integer): Boolean; 92 function TryBinToInt(Data: string; out Value: Integer): Boolean; 93 procedure SortStrings(Strings: TStrings); 73 94 74 95 … … 98 119 I: Integer; 99 120 begin 121 Result := ''; 100 122 for I := 1 to Length(Source) do begin 101 123 Result := Result + LowerCase(IntToHex(Ord(Source[I]), 2)); … … 112 134 Path := IncludeTrailingPathDelimiter(APath); 113 135 114 Find := FindFirst( UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);136 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 115 137 while Find = 0 do begin 116 DeleteFile(Path + UTF8Encode(SearchRec.Name));138 DeleteFile(Path + SearchRec.Name); 117 139 118 140 Find := SysUtils.FindNext(SearchRec); … … 185 207 end;*) 186 208 209 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 210 var 211 I: Integer; 212 begin 213 Result := ''; 214 for I := 0 to List.Count - 1 do begin 215 Result := Result + Around + List[I] + Around; 216 if I < List.Count - 1 then Result := Result + Separator; 217 end; 218 end; 219 187 220 function LastPos(const SubStr: String; const S: String): Integer; 188 221 begin … … 230 263 end; 231 264 232 function TryHexToInt(Data: string; varValue: Integer): Boolean;265 function TryHexToInt(Data: string; out Value: Integer): Boolean; 233 266 var 234 267 I: Integer; … … 246 279 end; 247 280 248 function TryBinToInt(Data: string; varValue: Integer): Boolean;281 function TryBinToInt(Data: string; out Value: Integer): Boolean; 249 282 var 250 283 I: Integer; … … 274 307 end; 275 308 276 function Explode(Separator: char; Data: string): TArrayOfString; 277 begin 278 SetLength(Result, 0); 279 while Pos(Separator, Data) > 0 do begin 309 function Explode(Separator: Char; Data: string): TStringArray; 310 var 311 Index: Integer; 312 begin 313 Result := Default(TStringArray); 314 repeat 315 Index := Pos(Separator, Data); 316 if Index > 0 then begin 317 SetLength(Result, Length(Result) + 1); 318 Result[High(Result)] := Copy(Data, 1, Index - 1); 319 Delete(Data, 1, Index); 320 end else Break; 321 until False; 322 if Data <> '' then begin 280 323 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} 324 Result[High(Result)] := Data; 325 end; 326 end; 327 328 function Implode(Separator: string; List: TList<string>): string; 329 var 330 I: Integer; 331 begin 332 Result := ''; 333 for I := 0 to List.Count - 1 do begin 334 Result := Result + List[I]; 335 if I < List.Count - 1 then Result := Result + Separator; 336 end; 337 end; 338 339 {$IFDEF WINDOWS} 289 340 function GetUserName: string; 290 341 const … … 294 345 begin 295 346 L := MAX_USERNAME_LENGTH + 2; 347 Result := Default(string); 296 348 SetLength(Result, L); 297 349 if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin … … 307 359 end; 308 360 end; 309 {$ endif}361 {$ENDIF} 310 362 311 363 function ComputerName: string; 312 {$ ifdef mswindows}364 {$IFDEF WINDOWS} 313 365 const 314 366 INFO_BUFFER_SIZE = 32767; … … 325 377 end; 326 378 end; 327 {$ endif}328 {$ ifdef unix}379 {$ENDIF} 380 {$IFDEF UNIX} 329 381 var 330 382 Name: UtsName; 331 383 begin 384 Name := Default(UtsName); 332 385 fpuname(Name); 333 386 Result := Name.Nodename; 334 387 end; 335 {$ endif}336 337 {$ ifdef windows}388 {$ENDIF} 389 390 {$IFDEF WINDOWS} 338 391 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 339 392 const … … 413 466 procedure LoadLibraries; 414 467 begin 415 {$IFDEF W indows}468 {$IFDEF WINDOWS} 416 469 DLLHandle1 := LoadLibrary('secur32.dll'); 417 470 if DLLHandle1 <> 0 then … … 424 477 procedure FreeLibraries; 425 478 begin 426 {$IFDEF W indows}479 {$IFDEF WINDOWS} 427 480 if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1); 428 481 {$ENDIF} 429 482 end; 430 483 431 procedure ExecuteProgram( CommandLine:string);484 procedure ExecuteProgram(Executable: string; Parameters: array of string); 432 485 var 433 486 Process: TProcess; 487 I: Integer; 434 488 begin 435 489 try 436 490 Process := TProcess.Create(nil); 437 Process.CommandLine := CommandLine; 491 Process.Executable := Executable; 492 for I := 0 to Length(Parameters) - 1 do 493 Process.Parameters.Add(Parameters[I]); 438 494 Process.Options := [poNoConsole]; 439 495 Process.Execute; … … 454 510 end; 455 511 512 procedure OpenEmail(Email: string); 513 begin 514 OpenURL('mailto:' + Email); 515 end; 516 456 517 procedure OpenFileInShell(FileName: string); 457 518 begin 458 ExecuteProgram('cmd.exe /c start "' + FileName + '"');519 ExecuteProgram('cmd.exe', ['/c', 'start', FileName]); 459 520 end; 460 521 … … 482 543 end; 483 544 484 function MergeArray(A, B: array of string): TArrayOfString; 485 var 486 I: Integer; 487 begin 545 function MergeArray(A, B: array of string): TStringArray; 546 var 547 I: Integer; 548 begin 549 Result := Default(TStringArray); 488 550 SetLength(Result, Length(A) + Length(B)); 489 551 for I := 0 to Length(A) - 1 do … … 511 573 end; 512 574 575 function DefaultSearchFilter(const FileName: string): Boolean; 576 begin 577 Result := True; 578 end; 579 580 procedure SaveStringToFile(S, FileName: string); 581 var 582 F: TextFile; 583 begin 584 AssignFile(F, FileName); 585 try 586 ReWrite(F); 587 Write(F, S); 588 finally 589 CloseFile(F); 590 end; 591 end; 592 593 procedure SearchFiles(AList: TStrings; Dir: string; 594 FilterMethod: TFilterMethod = nil; FileNameMethod: TFileNameMethod = nil); 595 var 596 SR: TSearchRec; 597 begin 598 Dir := IncludeTrailingPathDelimiter(Dir); 599 if FindFirst(Dir + '*', faAnyFile, SR) = 0 then 600 try 601 repeat 602 if (SR.Name = '.') or (SR.Name = '..') or (Assigned(FilterMethod) and (not FilterMethod(SR.Name) or 603 not FilterMethod(Copy(Dir, 3, Length(Dir)) + SR.Name))) then Continue; 604 if Assigned(FileNameMethod) then 605 FileNameMethod(Dir + SR.Name); 606 AList.Add(Dir + SR.Name); 607 if (SR.Attr and faDirectory) <> 0 then 608 SearchFiles(AList, Dir + SR.Name, FilterMethod); 609 until FindNext(SR) <> 0; 610 finally 611 FindClose(SR); 612 end; 613 end; 614 615 function GetStringPart(var Text: string; Separator: string): string; 616 var 617 P: Integer; 618 begin 619 P := Pos(Separator, Text); 620 if P > 0 then begin 621 Result := Copy(Text, 1, P - 1); 622 Delete(Text, 1, P - 1 + Length(Separator)); 623 end else begin 624 Result := Text; 625 Text := ''; 626 end; 627 Result := Trim(Result); 628 Text := Trim(Text); 629 end; 630 631 function StripTags(const S: string): string; 632 var 633 Len: Integer; 634 635 function ReadUntil(const ReadFrom: Integer; const C: Char): Integer; 636 var 637 J: Integer; 638 begin 639 for J := ReadFrom to Len do 640 if (S[j] = C) then 641 begin 642 Result := J; 643 Exit; 644 end; 645 Result := Len + 1; 646 end; 647 648 var 649 I, APos: Integer; 650 begin 651 Len := Length(S); 652 I := 0; 653 Result := ''; 654 while (I <= Len) do begin 655 Inc(I); 656 APos := ReadUntil(I, '<'); 657 Result := Result + Copy(S, I, APos - i); 658 I := ReadUntil(APos + 1, '>'); 659 end; 660 end; 661 662 function PosFromIndex(SubStr: string; Text: string; 663 StartIndex: Integer): Integer; 664 var 665 I, MaxLen: SizeInt; 666 Ptr: PAnsiChar; 667 begin 668 Result := 0; 669 if (StartIndex < 1) or (StartIndex > Length(Text) - Length(SubStr)) then Exit; 670 if Length(SubStr) > 0 then begin 671 MaxLen := Length(Text) - Length(SubStr) + 1; 672 I := StartIndex; 673 Ptr := @Text[StartIndex]; 674 while (I <= MaxLen) do begin 675 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 676 Result := I; 677 Exit; 678 end; 679 Inc(I); 680 Inc(Ptr); 681 end; 682 end; 683 end; 684 685 function PosFromIndexReverse(SubStr: string; Text: string; 686 StartIndex: Integer): Integer; 687 var 688 I: SizeInt; 689 Ptr: PAnsiChar; 690 begin 691 Result := 0; 692 if (StartIndex < 1) or (StartIndex > Length(Text)) then Exit; 693 if Length(SubStr) > 0 then begin 694 I := StartIndex; 695 Ptr := @Text[StartIndex]; 696 while (I > 0) do begin 697 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 698 Result := I; 699 Exit; 700 end; 701 Dec(I); 702 Dec(Ptr); 703 end; 704 end; 705 end; 706 707 procedure CopyStringArray(Dest: TStringArray; Source: array of string); 708 var 709 I: Integer; 710 begin 711 SetLength(Dest, Length(Source)); 712 for I := 0 to Length(Dest) - 1 do 713 Dest[I] := Source[I]; 714 end; 715 716 function CombinePaths(Path1, Path2: string): string; 717 begin 718 Result := Path1; 719 if Result <> '' then Result := Result + DirectorySeparator + Path2 720 else Result := Path2; 721 end; 722 723 procedure SortStrings(Strings: TStrings); 724 var 725 Tmp: TStringList; 726 begin 727 Strings.BeginUpdate; 728 try 729 if Strings is TStringList then begin 730 TStringList(Strings).Sort; 731 end else begin 732 Tmp := TStringList.Create; 733 try 734 Tmp.Assign(Strings); 735 Tmp.Sort; 736 Strings.Assign(Tmp); 737 finally 738 Tmp.Free; 739 end; 740 end; 741 finally 742 Strings.EndUpdate; 743 end; 744 end; 513 745 514 746 -
trunk/Packages/Common/CommonPackage.pas
r74 r75 3 3 } 4 4 5 unit Common ;5 unit CommonPackage; 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, LazarusPackageIntf; 11 StopWatch, Common, DebugLog, Common.Delay, PrefixMultiplier, URI, Threading, 12 Memory, ResetableThread, Pool, LastOpenedList, RegistryEx, JobProgressView, 13 XML, ApplicationInfo, SyncCounter, ListViewSort, PersistentForm, FindFile, 14 ScaleDPI, Theme, StringTable, MetaCanvas, Geometric, Translator, Languages, 15 PixelPointer, DataFile, TestCase, Generics, Table, FormEx, FormTests, 16 FormTest, FormAbout, LazarusPackageIntf; 14 17 15 18 implementation … … 17 20 procedure Register; 18 21 begin 19 RegisterUnit('UDebugLog', @UDebugLog.Register); 20 RegisterUnit('ULastOpenedList', @ULastOpenedList.Register); 21 RegisterUnit('UJobProgressView', @UJobProgressView.Register); 22 RegisterUnit('UApplicationInfo', @UApplicationInfo.Register); 23 RegisterUnit('UListViewSort', @UListViewSort.Register); 24 RegisterUnit('UPersistentForm', @UPersistentForm.Register); 25 RegisterUnit('UFindFile', @UFindFile.Register); 22 RegisterUnit('DebugLog', @DebugLog.Register); 23 RegisterUnit('PrefixMultiplier', @PrefixMultiplier.Register); 24 RegisterUnit('LastOpenedList', @LastOpenedList.Register); 25 RegisterUnit('JobProgressView', @JobProgressView.Register); 26 RegisterUnit('ApplicationInfo', @ApplicationInfo.Register); 27 RegisterUnit('ListViewSort', @ListViewSort.Register); 28 RegisterUnit('PersistentForm', @PersistentForm.Register); 29 RegisterUnit('FindFile', @FindFile.Register); 30 RegisterUnit('ScaleDPI', @ScaleDPI.Register); 31 RegisterUnit('Theme', @Theme.Register); 32 RegisterUnit('Translator', @Translator.Register); 33 RegisterUnit('FormEx', @FormEx.Register); 26 34 end; 27 35 -
trunk/Packages/Common/DebugLog.pas
r74 r75 1 unit UDebugLog; 2 3 {$mode delphi} 1 unit DebugLog; 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; 132 134 133 135 end. 134 -
trunk/Packages/Common/FindFile.pas
r74 r75 19 19 } 20 20 21 unit UFindFile;21 unit FindFile; 22 22 23 23 interface 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 … … 55 52 end; 56 53 54 const 55 {$IFDEF WINDOWS} 56 FilterAll = '*.*'; 57 {$ENDIF} 58 {$IFDEF UNIX} 59 FilterAll = '*'; 60 {$ENDIF} 61 57 62 procedure Register; 63 58 64 59 65 implementation … … 71 77 inherited Create(AOwner); 72 78 Path := IncludeTrailingBackslash(UTF8Encode(GetCurrentDir)); 73 FileMask := '*.*';79 FileMask := FilterAll; 74 80 FileAttr := [ffaAnyFile]; 75 81 s := TStringList.Create; … … 79 85 begin 80 86 s.Free; 81 inherited Destroy;87 inherited; 82 88 end; 83 89 … … 109 115 Attr := 0; 110 116 if ffaReadOnly in FileAttr then Attr := Attr + faReadOnly; 111 if ffaHidden in FileAttr then Attr := Attr + faHidden;112 if ffaSysFile in FileAttr then Attr := Attr + faSysFile;113 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; 114 120 if ffaDirectory in FileAttr then Attr := Attr + faDirectory; 115 121 if ffaArchive in FileAttr then Attr := Attr + faArchive; 116 122 if ffaAnyFile in FileAttr then Attr := Attr + faAnyFile; 117 123 118 if SysUtils.FindFirst( UTF8Decode(inPath + FileMask), Attr, Rec) = 0 then124 if SysUtils.FindFirst(inPath + FileMask, Attr, Rec) = 0 then 119 125 try 120 126 repeat 121 s.Add(inPath + UTF8Encode(Rec.Name));127 s.Add(inPath + Rec.Name); 122 128 until SysUtils.FindNext(Rec) <> 0; 123 129 finally … … 127 133 If not InSubFolders then Exit; 128 134 129 if SysUtils.FindFirst( UTF8Decode(inPath + '*.*'), faDirectory, Rec) = 0 then135 if SysUtils.FindFirst(inPath + FilterAll, faDirectory, Rec) = 0 then 130 136 try 131 137 repeat 132 138 if ((Rec.Attr and faDirectory) > 0) and (Rec.Name <> '.') 133 139 and (Rec.Name <> '..') then 134 FileSearch(IncludeTrailingBackslash(inPath + UTF8Encode(Rec.Name)));140 FileSearch(IncludeTrailingBackslash(inPath + Rec.Name)); 135 141 until SysUtils.FindNext(Rec) <> 0; 136 142 finally 137 143 SysUtils.FindClose(Rec); 138 144 end; 139 end; 145 end; 140 146 141 147 end. 142 -
trunk/Packages/Common/JobProgressView.lfm
r74 r75 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.1'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/JobProgressView.pas
r74 r75 1 unit UJobProgressView; 2 3 {$MODE Delphi} 1 unit JobProgressView; 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, Threading, 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 … … 148 154 end; 149 155 150 //var151 // FormJobProgressView: TFormJobProgressView;152 153 156 procedure Register; 154 157 155 158 resourcestring 156 159 SExecuted = 'Executed'; 160 157 161 158 162 implementation … … 172 176 end; 173 177 178 { TJobThread } 179 174 180 procedure TJobThread.Execute; 175 181 begin 176 182 try 177 183 try 178 //raise Exception.Create('Exception in job');179 184 ProgressView.CurrentJob.Method(Job); 180 185 except … … 189 194 end; 190 195 191 procedure TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod; 192 NoThreaded: Boolean = False; WaitFor: Boolean = False); 196 { TFormJobProgressView } 197 198 procedure TFormJobProgressView.UpdateHeight; 193 199 var 194 NewJob: TJob; 195 begin 196 NewJob := TJob.Create; 197 NewJob.ProgressView := Self; 198 NewJob.Title := Title; 199 NewJob.Method := Method; 200 NewJob.NoThreaded := NoThreaded; 201 NewJob.WaitFor := WaitFor; 202 NewJob.Progress.Max := 100; 203 NewJob.Progress.Reset; 204 NewJob.Progress.OnChange := JobProgressChange; 205 Jobs.Add(NewJob); 200 H: Integer; 201 PanelOperationsVisible: Boolean; 202 PanelOperationsHeight: Integer; 203 PanelProgressVisible: Boolean; 204 PanelProgressTotalVisible: Boolean; 205 PanelLogVisible: Boolean; 206 MemoLogHeight: Integer = 200; 207 I: Integer; 208 ItemRect: TRect; 209 MaxH: Integer; 210 begin 211 H := PanelOperationsTitle.Height; 212 PanelOperationsVisible := JobProgressView.Jobs.Count > 0; 213 if PanelOperationsVisible <> PanelOperations.Visible then 214 PanelOperations.Visible := PanelOperationsVisible; 215 if ListViewJobs.Items.Count > 0 then begin 216 Maxh := 0; 217 for I := 0 to ListViewJobs.Items.Count - 1 do 218 begin 219 ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds); 220 Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top)); 221 end; 222 PanelOperationsHeight := Scale96ToScreen(12) + Maxh; 223 end else PanelOperationsHeight := Scale96ToScreen(8); 224 if PanelOperationsHeight <> PanelOperations.Height then 225 PanelOperations.Height := PanelOperationsHeight; 226 if PanelOperationsVisible then 227 H := H + PanelOperations.Height; 228 229 PanelProgressVisible := (JobProgressView.Jobs.Count > 0) and not JobProgressView.Finished; 230 if PanelProgressVisible <> PanelProgress.Visible then 231 PanelProgress.Visible := PanelProgressVisible; 232 if PanelProgressVisible then 233 H := H + PanelProgress.Height; 234 PanelProgressTotalVisible := (JobProgressView.Jobs.Count > 1) and not JobProgressView.Finished; 235 if PanelProgressTotalVisible <> PanelProgressTotal.Visible then 236 PanelProgressTotal.Visible := PanelProgressTotalVisible; 237 if PanelProgressTotalVisible then 238 H := H + PanelProgressTotal.Height; 239 Constraints.MinHeight := H; 240 PanelLogVisible := MemoLog.Lines.Count > 0; 241 if PanelLogVisible <> PanelLog.Visible then 242 PanelLog.Visible := PanelLogVisible; 243 if PanelLogVisible then 244 H := H + Scale96ToScreen(MemoLogHeight); 245 if PanelText.Visible then 246 H := H + PanelText.Height; 247 if Height <> H then begin 248 Height := H; 249 Top := (Screen.Height - H) div 2; 250 end; 251 end; 252 253 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject); 254 var 255 ProgressBarPartVisible: Boolean; 256 ProgressBarTotalVisible: Boolean; 257 begin 258 JobProgressView.UpdateProgress; 259 if Visible and (not ProgressBarPart.Visible) and 260 Assigned(JobProgressView.CurrentJob) and 261 (JobProgressView.CurrentJob.Progress.Value > 0) then begin 262 ProgressBarPartVisible := True; 263 if ProgressBarPartVisible <> ProgressBarPart.Visible then 264 ProgressBarPart.Visible := ProgressBarPartVisible; 265 ProgressBarTotalVisible := True; 266 if ProgressBarTotalVisible <> ProgressBarTotal.Visible then 267 ProgressBarTotal.Visible := ProgressBarTotalVisible; 268 end; 269 if not Visible then begin 270 TimerUpdate.Interval := UpdateInterval; 271 if not JobProgressView.OwnerDraw then Show; 272 end; 273 if Assigned(JobProgressView.CurrentJob) then begin 274 LabelText.Caption := JobProgressView.CurrentJob.Progress.Text; 275 if LabelText.Caption <> '' then begin 276 PanelText.Visible := True; 277 UpdateHeight; 278 end; 279 end; 280 end; 281 282 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem); 283 begin 284 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then 285 with JobProgressView.Jobs[Item.Index] do begin 286 Item.Caption := Title; 287 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1 288 else if Finished then Item.ImageIndex := 0 289 else Item.ImageIndex := 2; 290 Item.Data := JobProgressView.Jobs[Item.Index]; 291 end; 292 end; 293 294 procedure TFormJobProgressView.FormClose(Sender: TObject; 295 var CloseAction: TCloseAction); 296 begin 297 end; 298 299 procedure TFormJobProgressView.FormCreate(Sender: TObject); 300 begin 301 Caption := SPleaseWait; 302 try 303 //Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) + 304 // DirectorySeparator + 'horse.avi'; 305 //Animate1.Active := True; 306 except 307 308 end; 309 end; 310 311 procedure TFormJobProgressView.ReloadJobList; 312 begin 313 // Workaround for not showing first line 314 //Form.ListViewJobs.Items.Count := Jobs.Count + 1; 315 //Form.ListViewJobs.Refresh; 316 317 if ListViewJobs.Items.Count <> JobProgressView.Jobs.Count then 318 ListViewJobs.Items.Count := JobProgressView.Jobs.Count; 319 ListViewJobs.Refresh; 320 Application.ProcessMessages; 321 UpdateHeight; 322 end; 323 324 procedure TFormJobProgressView.FormShow(Sender: TObject); 325 begin 326 ReloadJobList; 327 end; 328 329 procedure TFormJobProgressView.FormHide(Sender: TObject); 330 begin 331 JobProgressView.Jobs.Clear; 332 ReloadJobList; 333 end; 334 335 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 336 begin 337 CanClose := JobProgressView.Finished; 338 JobProgressView.Terminate := True; 339 Caption := SPleaseWait + STerminate; 340 end; 341 342 343 { TJobProgressView } 344 345 function TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod; 346 NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob; 347 begin 348 Result := TJob.Create; 349 Result.ProgressView := Self; 350 Result.Title := Title; 351 Result.Method := Method; 352 Result.NoThreaded := NoThreaded; 353 Result.WaitFor := WaitFor; 354 Result.Progress.Max := 100; 355 Result.Progress.Reset; 356 Result.Progress.OnChange := JobProgressChange; 357 Jobs.Add(Result); 206 358 //ReloadJobList; 207 359 end; 208 360 209 procedure TJobProgressView.Start(AAutoClose: Boolean = True); 210 begin 211 AutoClose := AAutoClose; 212 StartJobs; 213 end; 214 215 procedure TJobProgressView.StartJobs; 361 procedure TJobProgressView.Start; 216 362 var 217 363 I: Integer; … … 228 374 Form.MemoLog.Clear; 229 375 376 Form.PanelText.Visible := False; 230 377 Form.LabelEstimatedTimePart.Visible := False; 231 378 Form.LabelEstimatedTimeTotal.Visible := False; … … 248 395 I := 0; 249 396 while I < Jobs.Count do 250 with TJob(Jobs[I])do begin397 with Jobs[I] do begin 251 398 CurrentJobIndex := I; 252 CurrentJob := TJob(Jobs[I]);399 CurrentJob := Jobs[I]; 253 400 JobProgressChange(Self); 254 401 StartTime := Now; … … 257 404 Form.ProgressBarPart.Visible := False; 258 405 //Show; 259 ReloadJobList;406 Form.ReloadJobList; 260 407 Application.ProcessMessages; 261 408 if NoThreaded then begin … … 263 410 Method(CurrentJob); 264 411 end else begin 412 Thread := TJobThread.Create(True); 265 413 try 266 Thread := TJobThread.Create(True);267 414 with Thread do begin 268 415 FreeOnTerminate := False; … … 295 442 //if Visible then Hide; 296 443 Form.MemoLog.Lines.Assign(Log); 297 if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin444 if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin 298 445 Form.Hide; 299 446 end; 300 Clear;447 if not Form.Visible then Clear; 301 448 Form.Caption := SFinished; 302 449 //LabelEstimatedTimePart.Visible := False; 303 450 Finished := True; 304 451 CurrentJobIndex := -1; 305 ReloadJobList; 306 end; 307 end; 308 309 procedure TJobProgressView.UpdateHeight; 310 var 311 H: Integer; 312 PanelOperationsVisible: Boolean; 313 PanelOperationsHeight: Integer; 314 PanelProgressVisible: Boolean; 315 PanelProgressTotalVisible: Boolean; 316 PanelLogVisible: Boolean; 317 begin 318 with Form do begin 319 H := PanelOperationsTitle.Height; 320 PanelOperationsVisible := Jobs.Count > 0; 321 if PanelOperationsVisible <> PanelOperations.Visible then 322 PanelOperations.Visible := PanelOperationsVisible; 323 PanelOperationsHeight := 8 + 18 * Jobs.Count; 324 if PanelOperationsHeight <> PanelOperations.Height then 325 PanelOperations.Height := PanelOperationsHeight; 326 if PanelOperationsVisible then 327 H := H + PanelOperations.Height; 328 329 PanelProgressVisible := (Jobs.Count > 0) and not Finished; 330 if PanelProgressVisible <> PanelProgress.Visible then 331 PanelProgress.Visible := PanelProgressVisible; 332 if PanelProgressVisible then 333 H := H + PanelProgress.Height; 334 PanelProgressTotalVisible := (Jobs.Count > 1) and not Finished; 335 if PanelProgressTotalVisible <> PanelProgressTotal.Visible then 336 PanelProgressTotal.Visible := PanelProgressTotalVisible; 337 if PanelProgressTotalVisible then 338 H := H + PanelProgressTotal.Height; 339 Constraints.MinHeight := H; 340 PanelLogVisible := MemoLog.Lines.Count > 0; 341 if PanelLogVisible <> PanelLog.Visible then 342 PanelLog.Visible := PanelLogVisible; 343 if PanelLogVisible then 344 H := H + MemoLogHeight; 345 if Height <> H then Height := H; 452 Form.ReloadJobList; 346 453 end; 347 454 end; … … 351 458 if Assigned(FOnOwnerDraw) then 352 459 FOnOwnerDraw(Self); 353 end;354 355 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject);356 var357 ProgressBarPartVisible: Boolean;358 ProgressBarTotalVisible: Boolean;359 begin360 JobProgressView.UpdateProgress;361 if Visible and (not ProgressBarPart.Visible) and362 Assigned(JobProgressView.CurrentJob) and363 (JobProgressView.CurrentJob.Progress.Value > 0) then begin364 ProgressBarPartVisible := True;365 if ProgressBarPartVisible <> ProgressBarPart.Visible then366 ProgressBarPart.Visible := ProgressBarPartVisible;367 ProgressBarTotalVisible := True;368 if ProgressBarTotalVisible <> ProgressBarTotal.Visible then369 ProgressBarTotal.Visible := ProgressBarTotalVisible;370 end;371 if not Visible then begin372 TimerUpdate.Interval := UpdateInterval;373 if not JobProgressView.OwnerDraw then Show;374 end;375 end;376 377 procedure TFormJobProgressView.FormDestroy(Sender:TObject);378 begin379 end;380 381 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem);382 begin383 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then384 with TJob(JobProgressView.Jobs[Item.Index]) do begin385 Item.Caption := Title;386 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1387 else if Finished then Item.ImageIndex := 0388 else Item.ImageIndex := 2;389 Item.Data := JobProgressView.Jobs[Item.Index];390 end;391 end;392 393 procedure TFormJobProgressView.FormClose(Sender: TObject;394 var CloseAction: TCloseAction);395 begin396 ListViewJobs.Clear;397 end;398 399 procedure TFormJobProgressView.FormCreate(Sender: TObject);400 begin401 Caption := SPleaseWait;402 try403 //Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) +404 // DirectorySeparator + 'horse.avi';405 //Animate1.Active := True;406 except407 408 end;409 460 end; 410 461 … … 427 478 end; 428 479 429 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean);430 begin431 CanClose := JobProgressView.Finished;432 JobProgressView.Terminate := True;433 Caption := SPleaseWait + STerminate;434 end;435 436 480 procedure TJobProgressView.SetTerminate(const AValue: Boolean); 437 481 var … … 440 484 if AValue = FTerminate then Exit; 441 485 for I := 0 to Jobs.Count - 1 do 442 TJob(Jobs[I]).Terminate := AValue;486 Jobs[I].Terminate := AValue; 443 487 FTerminate := AValue; 444 488 end; … … 489 533 end; 490 534 491 procedure TJobProgressView.ReloadJobList;492 begin493 UpdateHeight;494 // Workaround for not showing first line495 Form.ListViewJobs.Items.Count := Jobs.Count + 1;496 Form.ListViewJobs.Refresh;497 498 if Form.ListViewJobs.Items.Count <> Jobs.Count then499 Form.ListViewJobs.Items.Count := Jobs.Count;500 Form.ListViewJobs.Refresh;501 //Application.ProcessMessages;502 end;503 504 535 constructor TJobProgressView.Create(TheOwner: TComponent); 505 536 begin 506 537 inherited; 507 538 if not (csDesigning in ComponentState) then begin 508 F orm := TFormJobProgressView.Create(Self);509 F orm.JobProgressView := Self;510 end; 511 Jobs := T ObjectList.Create;539 FForm := TFormJobProgressView.Create(Self); 540 FForm.JobProgressView := Self; 541 end; 542 Jobs := TJobs.Create; 512 543 Log := TStringList.Create; 513 544 //PanelOperationsTitle.Height := 80; 514 ShowDelay := 0; //1000; // ms 545 AutoClose := True; 546 ShowDelay := 0; 515 547 end; 516 548 … … 518 550 begin 519 551 Jobs.Clear; 552 Log.Clear; 520 553 //ReloadJobList; 521 554 end; … … 527 560 inherited; 528 561 end; 562 563 { TProgress } 529 564 530 565 procedure TProgress.SetMax(const AValue: Integer); … … 535 570 if FMax < 1 then FMax := 1; 536 571 if FValue >= FMax then FValue := FMax; 572 finally 573 FLock.Release; 574 end; 575 end; 576 577 procedure TProgress.SetText(AValue: string); 578 begin 579 try 580 FLock.Acquire; 581 if FText = AValue then Exit; 582 FText := AValue; 537 583 finally 538 584 FLock.Release; … … 562 608 end; 563 609 564 { TProgress }565 566 610 procedure TProgress.Increment; 567 611 begin 568 try569 FLock.Acquire;612 FLock.Acquire; 613 try 570 614 Value := Value + 1; 571 615 finally … … 576 620 procedure TProgress.Reset; 577 621 begin 578 try579 FLock.Acquire;622 FLock.Acquire; 623 try 580 624 FValue := 0; 581 625 finally … … 593 637 begin 594 638 FLock.Free; 595 inherited Destroy;639 inherited; 596 640 end; 597 641 … … 624 668 destructor TJob.Destroy; 625 669 begin 626 Progress.Free;670 FreeAndNil(Progress); 627 671 inherited; 628 672 end; -
trunk/Packages/Common/Languages/DebugLog.cs.po
r74 r75 1 1 msgid "" 2 2 msgstr "" 3 "Content-Type: text/plain; charset=UTF-8\n"4 3 "Project-Id-Version: \n" 5 4 "POT-Creation-Date: \n" … … 7 6 "Last-Translator: Jiří Hajda <robie@centrum.cz>\n" 8 7 "Language-Team: \n" 8 "Language: cs\n" 9 9 "MIME-Version: 1.0\n" 10 "Content-Type: text/plain; charset=UTF-8\n" 10 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 3.0.1\n" 11 13 12 #: udebuglog.sfilenamenotdefined 14 #: debuglog.sfilenamenotdefined 15 msgctxt "debuglog.sfilenamenotdefined" 13 16 msgid "Filename not defined" 14 17 msgstr "Neurčen soubor" -
trunk/Packages/Common/Languages/Pool.cs.po
r74 r75 1 1 msgid "" 2 2 msgstr "" 3 "Content-Type: text/plain; charset=UTF-8\n"4 3 "Project-Id-Version: \n" 5 4 "POT-Creation-Date: \n" … … 7 6 "Last-Translator: Chronos <robie@centrum.cz>\n" 8 7 "Language-Team: \n" 8 "Language: cs\n" 9 9 "MIME-Version: 1.0\n" 10 "Content-Type: text/plain; charset=UTF-8\n" 10 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 3.0.1\n" 11 13 12 #: upool.sobjectpoolempty 14 #: pool.sobjectpoolempty 15 msgctxt "pool.sobjectpoolempty" 13 16 msgid "Object pool is empty" 14 17 msgstr "Zásobník objektů je prázdný" 15 18 16 #: upool.sreleaseerror 19 #: pool.sreleaseerror 20 msgctxt "pool.sreleaseerror" 17 21 msgid "Unknown object for release from pool" 18 22 msgstr "Neznýmý objekt pro uvolnění ze zásobníku" -
trunk/Packages/Common/Languages/ResetableThread.cs.po
r74 r75 1 1 msgid "" 2 2 msgstr "" 3 "Content-Type: text/plain; charset=UTF-8\n"4 3 "Project-Id-Version: \n" 5 4 "POT-Creation-Date: \n" … … 7 6 "Last-Translator: Chronos <robie@centrum.cz>\n" 8 7 "Language-Team: \n" 8 "Language: cs\n" 9 9 "MIME-Version: 1.0\n" 10 "Content-Type: text/plain; charset=UTF-8\n" 10 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 3.0.1\n" 11 13 12 #: uresetablethread.swaiterror 14 #: resetablethread.swaiterror 15 msgctxt "resetablethread.swaiterror" 13 16 msgid "WaitFor error" 14 17 msgstr "Chyba WaitFor" -
trunk/Packages/Common/Languages/Threading.cs.po
r74 r75 1 1 msgid "" 2 2 msgstr "" 3 "Content-Type: text/plain; charset=UTF-8\n"4 3 "Project-Id-Version: \n" 5 4 "POT-Creation-Date: \n" … … 7 6 "Last-Translator: Chronos <robie@centrum.cz>\n" 8 7 "Language-Team: \n" 8 "Language: cs\n" 9 9 "MIME-Version: 1.0\n" 10 "Content-Type: text/plain; charset=UTF-8\n" 10 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 3.0.1\n" 11 13 12 #: uthreading.scurrentthreadnotfound 14 #: threading.scurrentthreadnotfound 15 #, object-pascal-format 16 msgctxt "threading.scurrentthreadnotfound" 13 17 msgid "Current thread ID %d not found in virtual thread list." 14 18 msgstr "Aktuální vlákno ID %d nenalezeno v seznamu virtuálních vláken." -
trunk/Packages/Common/LastOpenedList.pas
r74 r75 1 unit ULastOpenedList; 2 3 {$mode delphi} 1 unit LastOpenedList; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, Registry, URegistry, Menus;6 Classes, SysUtils, Registry, RegistryEx, Menus, XMLConf, DOM; 9 7 10 8 type … … 27 25 procedure LoadFromRegistry(Context: TRegistryContext); 28 26 procedure SaveToRegistry(Context: TRegistryContext); 27 procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string); 28 procedure SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 29 29 procedure AddItem(FileName: string); 30 function GetFirstFileName: string; 30 31 published 31 32 property MaxCount: Integer read FMaxCount write SetMaxCount; … … 81 82 destructor TLastOpenedList.Destroy; 82 83 begin 83 Items.Free;84 FreeAndNil(Items); 84 85 inherited; 85 86 end; … … 91 92 begin 92 93 if Assigned(MenuItem) then begin 93 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; 94 100 for I := 0 to Items.Count - 1 do begin 95 NewMenuItem := TMenuItem.Create(MenuItem); 96 NewMenuItem.Caption := Items[I]; 97 NewMenuItem.OnClick := ClickAction; 98 MenuItem.Add(NewMenuItem); 101 MenuItem.Items[I].Caption := Items[I]; 102 MenuItem.Items[I].OnClick := ClickAction; 99 103 end; 100 104 end; … … 137 141 OpenKey(Context.Key, True); 138 142 for I := 0 to Items.Count - 1 do 139 WriteString('File' + IntToStr(I), UTF8Decode(Items[I]));143 WriteString('File' + IntToStr(I), Items[I]); 140 144 finally 141 145 Free; 146 end; 147 end; 148 149 procedure TLastOpenedList.LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string 150 ); 151 var 152 I: Integer; 153 Value: string; 154 Count: Integer; 155 begin 156 with XMLConfig do begin 157 Count := GetValue(DOMString(Path + '/Count'), 0); 158 if Count > MaxCount then Count := MaxCount; 159 Items.Clear; 160 for I := 0 to Count - 1 do begin 161 Value := string(GetValue(DOMString(Path + '/File' + IntToStr(I)), '')); 162 if Trim(Value) <> '' then Items.Add(Value); 163 end; 164 if Assigned(FOnChange) then 165 FOnChange(Self); 166 end; 167 end; 168 169 procedure TLastOpenedList.SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 170 var 171 I: Integer; 172 begin 173 with XMLConfig do begin 174 SetValue(DOMString(Path + '/Count'), Items.Count); 175 for I := 0 to Items.Count - 1 do 176 SetValue(DOMString(Path + '/File' + IntToStr(I)), DOMString(Items[I])); 177 Flush; 142 178 end; 143 179 end; … … 151 187 end; 152 188 189 function TLastOpenedList.GetFirstFileName: string; 190 begin 191 if Items.Count > 0 then Result := Items[0] 192 else Result := ''; 193 end; 194 153 195 end. 154 -
trunk/Packages/Common/ListViewSort.pas
r74 r75 1 unit UListViewSort; 2 3 // Date: 2010-11-03 4 5 {$mode delphi} 1 unit ListViewSort; 2 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; 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; 12 11 13 12 type … … 18 17 TCompareEvent = function (Item1, Item2: TObject): Integer of object; 19 18 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 19 20 TObjects = TObjectList<TObject>; 21 22 { TListViewSort } 20 23 21 24 TListViewSort = class(TComponent) … … 28 31 FColumn: Integer; 29 32 FOrder: TSortOrder; 33 FOldListViewWindowProc: TWndMethod; 34 FOnColumnWidthChanged: TNotifyEvent; 35 procedure DoColumnBeginResize(const AColIndex: Integer); 36 procedure DoColumnResized(const AColIndex: Integer); 37 procedure DoColumnResizing(const AColIndex, AWidth: Integer); 30 38 procedure SetListView(const Value: TListView); 31 39 procedure ColumnClick(Sender: TObject; Column: TListColumn); … … 40 48 procedure SetColumn(const Value: Integer); 41 49 procedure SetOrder(const Value: TSortOrder); 50 {$IFDEF WINDOWS} 51 procedure NewListViewWindowProc(var AMsg: TMessage); 52 {$ENDIF} 42 53 public 43 List: TListObject;44 Source: TListObject;54 Source: TObjects; 55 List: TObjects; 45 56 constructor Create(AOwner: TComponent); override; 46 57 destructor Destroy; override; … … 58 69 property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw 59 70 write FOnCustomDraw; 71 property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged 72 write FOnColumnWidthChanged; 60 73 property Column: Integer read FColumn write SetColumn; 61 74 property Order: TSortOrder read FOrder write SetOrder; … … 68 81 FOnChange: TNotifyEvent; 69 82 FStringGrid1: TStringGrid; 70 procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 83 procedure DoOnChange; 84 procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 85 procedure GridDoOnResize(Sender: TObject); 71 86 public 72 87 constructor Create(AOwner: TComponent); override; 73 88 procedure UpdateFromListView(ListView: TListView); 74 89 function TextEntered: Boolean; 90 function TextEnteredCount: Integer; 91 function TextEnteredColumn(Index: Integer): Boolean; 75 92 function GetColValue(Index: Integer): string; 93 procedure Reset; 76 94 property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1; 77 95 published … … 79 97 property Align; 80 98 property Anchors; 99 property BorderSpacing; 100 end; 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; 81 118 end; 82 119 … … 88 125 procedure Register; 89 126 begin 90 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; 91 152 end; 92 153 93 154 { TListViewFilter } 94 155 95 procedure TListViewFilter.DoOnKeyUp(Sender: TObject; var Key: Word; 156 procedure TListViewFilter.DoOnChange; 157 begin 158 if Assigned(FOnChange) then FOnChange(Self); 159 end; 160 161 procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word; 96 162 Shift: TShiftState); 97 163 begin 98 if Assigned(FOnChange) then 99 FOnChange(Self); 164 DoOnChange; 165 end; 166 167 procedure TListViewFilter.GridDoOnResize(Sender: TObject); 168 begin 169 FStringGrid1.DefaultRowHeight := FStringGrid1.Height; 100 170 end; 101 171 … … 113 183 FStringGrid1.Options := [goFixedHorzLine, goFixedVertLine, goVertLine, 114 184 goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]; 115 FStringGrid1.OnKeyUp := DoOnKeyUp; 185 FStringGrid1.OnKeyUp := GridDoOnKeyUp; 186 FStringGrid1.OnResize := GridDoOnResize; 116 187 end; 117 188 … … 119 190 var 120 191 I: Integer; 121 NewColumn: TGridColumn;192 R: TRect; 122 193 begin 123 194 with FStringGrid1 do begin 124 Columns.Clear;125 195 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 126 while Columns.Count < ListView.Columns.Count do NewColumn :=Columns.Add;196 while Columns.Count < ListView.Columns.Count do Columns.Add; 127 197 for I := 0 to ListView.Columns.Count - 1 do begin 128 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; 129 204 end; 130 205 end; … … 132 207 133 208 function TListViewFilter.TextEntered: Boolean; 209 begin 210 Result := TextEnteredCount > 0; 211 end; 212 213 function TListViewFilter.TextEnteredCount: Integer; 134 214 var 135 215 I: Integer; 136 216 begin 137 Result := False;217 Result := 0; 138 218 for I := 0 to FStringGrid1.ColCount - 1 do begin 139 219 if FStringGrid1.Cells[I, 0] <> '' then begin 140 Result := True; 141 Break; 220 Inc(Result); 142 221 end; 143 222 end; 223 end; 224 225 function TListViewFilter.TextEnteredColumn(Index: Integer): Boolean; 226 begin 227 Result := FStringGrid1.Cells[Index, 0] <> ''; 144 228 end; 145 229 … … 151 235 end; 152 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; 245 end; 246 153 247 { TListViewSort } 154 248 249 {$IFDEF WINDOWS} 250 procedure TListViewSort.NewListViewWindowProc(var AMsg: TMessage); 251 var 252 vColWidth: Integer; 253 vMsgNotify: TLMNotify absolute AMsg; 254 Code: Integer; 255 begin 256 // call the old WindowProc of ListView 257 FOldListViewWindowProc(AMsg); 258 259 // Currently we care only with WM_NOTIFY message 260 if AMsg.Msg = WM_NOTIFY then 261 begin 262 Code := NMHDR(PHDNotify(vMsgNotify.NMHdr)^.Hdr).Code; 263 case Code of 264 HDN_ENDTRACKA, HDN_ENDTRACKW: 265 DoColumnResized(PHDNotify(vMsgNotify.NMHdr)^.Item); 266 267 HDN_BEGINTRACKA, HDN_BEGINTRACKW: 268 DoColumnBeginResize(PHDNotify(vMsgNotify.NMHdr)^.Item); 269 270 HDN_TRACKA, HDN_TRACKW: 271 begin 272 vColWidth := -1; 273 if (PHDNotify(vMsgNotify.NMHdr)^.PItem<>nil) 274 and (PHDNotify(vMsgNotify.NMHdr)^.PItem^.Mask and HDI_WIDTH <> 0) 275 then 276 vColWidth := PHDNotify(vMsgNotify.NMHdr)^.PItem^.cxy; 277 278 DoColumnResizing(PHDNotify(vMsgNotify.NMHdr)^.Item, vColWidth); 279 end; 280 end; 281 end; 282 end; 283 {$ENDIF} 284 285 procedure TListViewSort.DoColumnBeginResize(const AColIndex: Integer); 286 begin 287 end; 288 289 procedure TListViewSort.DoColumnResizing(const AColIndex, AWidth: Integer); 290 begin 291 end; 292 293 procedure TListViewSort.DoColumnResized(const AColIndex: Integer); 294 begin 295 if Assigned(FOnColumnWidthChanged) then 296 FOnColumnWidthChanged(Self); 297 end; 155 298 156 299 procedure TListViewSort.ColumnClick(Sender: TObject; Column: TListColumn); … … 179 322 procedure TListViewSort.SetListView(const Value: TListView); 180 323 begin 324 if FListView = Value then Exit; 325 if Assigned(FListView) then 326 ListView.WindowProc := FOldListViewWindowProc; 181 327 FListView := Value; 182 328 FListView.OnColumnClick := ColumnClick; 183 329 FListView.OnCustomDrawItem := ListViewCustomDrawItem; 184 330 FListView.OnClick := ListViewClick; 331 FOldListViewWindowProc := FListView.WindowProc; 332 {$IFDEF WINDOWS} 333 FListView.WindowProc := NewListViewWindowProc; 334 {$ENDIF} 335 end; 336 337 var 338 ListViewSortCompare: TCompareEvent; 339 340 function ListViewCompare(constref Item1, Item2: TObject): Integer; 341 begin 342 Result := ListViewSortCompare(Item1, Item2); 185 343 end; 186 344 187 345 procedure TListViewSort.Sort(Compare: TCompareEvent); 188 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; 189 350 if (List.Count > 0) then 190 List.Sort( Compare);351 List.Sort(TComparer<TObject>.Construct(ListViewCompare)); 191 352 end; 192 353 … … 194 355 begin 195 356 if Assigned(FOnFilter) then FOnFilter(Self) 196 else if Assigned(Source) then 197 List.Assign(Source) else 357 else if Assigned(Source) then begin 198 358 List.Clear; 359 List.AddRange(Source); 360 end else List.Clear; 199 361 if ListView.Items.Count <> List.Count then 200 362 ListView.Items.Count := List.Count; 201 if Assigned(FOnCompareItem) then Sort(FOnCompareItem);363 if Assigned(FOnCompareItem) and (Order <> soNone) then Sort(FOnCompareItem); 202 364 //ListView.Items[-1]; // Workaround for not show first row if selected 203 365 ListView.Refresh; … … 251 413 begin 252 414 inherited; 253 List := T ListObject.Create;415 List := TObjects.Create; 254 416 List.OwnsObjects := False; 255 417 end; … … 257 419 destructor TListViewSort.Destroy; 258 420 begin 259 List.Free;421 FreeAndNil(List); 260 422 inherited; 261 423 end; … … 266 428 TP1: TPoint; 267 429 XBias, YBias: Integer; 268 OldColor: TColor; 430 PenColor: TColor; 431 BrushColor: TColor; 269 432 BiasTop, BiasLeft: Integer; 270 433 Rect1: TRect; … … 278 441 Item.Left := 0; 279 442 GetCheckBias(XBias, YBias, BiasTop, BiasLeft, ListView); 280 OldColor := ListView.Canvas.Pen.Color; 443 PenColor := ListView.Canvas.Pen.Color; 444 BrushColor := ListView.Canvas.Brush.Color; 281 445 //TP1 := Item.GetPosition; 282 446 lRect := Item.DisplayRect(drBounds); // Windows 7 workaround … … 290 454 ItemLeft := Item.Left; 291 455 ItemLeft := 23; // Windows 7 workaround 292 456 293 457 Rect1.Left := ItemLeft - CheckWidth - BiasLeft + 1 + XBias; 294 458 //ShowMessage(IntToStr(Tp1.Y) + ', ' + IntToStr(BiasTop) + ', ' + IntToStr(XBias)); … … 321 485 end; 322 486 //ListView.Canvas.Brush.Color := ListView.Color; 323 ListView.Canvas.Brush.Color := clWindow;324 ListView.Canvas.Pen.Color := OldColor;487 ListView.Canvas.Brush.Color := BrushColor; 488 ListView.Canvas.Pen.Color := PenColor; 325 489 end; 326 490 … … 389 553 FHeaderHandle := ListView_GetHeader(FListView.Handle); 390 554 for I := 0 to FListView.Columns.Count - 1 do begin 555 {$push}{$warn 5057 off} 391 556 FillChar(Item, SizeOf(THDItem), 0); 557 {$pop} 392 558 Item.Mask := HDI_FORMAT; 393 559 Header_GetItem(FHeaderHandle, I, Item); -
trunk/Packages/Common/Memory.pas
r74 r75 1 unit UMemory; 2 3 {$mode Delphi}{$H+} 1 unit Memory; 4 2 5 3 interface … … 24 22 constructor Create; 25 23 destructor Destroy; override; 24 procedure WriteMemory(Position: Integer; Memory: TMemory); 25 procedure ReadMemory(Position: Integer; Memory: TMemory); 26 26 property Data: PByte read FData; 27 27 property Size: Integer read FSize write SetSize; … … 42 42 end; 43 43 44 44 45 implementation 45 46 … … 48 49 procedure TPositionMemory.SetSize(AValue: Integer); 49 50 begin 50 inherited SetSize(AValue);51 inherited; 51 52 if FPosition > FSize then FPosition := FSize; 52 53 end; … … 105 106 begin 106 107 Size := 0; 107 inherited Destroy; 108 inherited; 109 end; 110 111 procedure TMemory.WriteMemory(Position: Integer; Memory: TMemory); 112 begin 113 Move(Memory.FData, PByte(PByte(@FData) + Position)^, Memory.Size); 114 end; 115 116 procedure TMemory.ReadMemory(Position: Integer; Memory: TMemory); 117 begin 118 Move(PByte(PByte(@FData) + Position)^, Memory.FData, Memory.Size); 108 119 end; 109 120 110 121 end. 111 -
trunk/Packages/Common/Pool.pas
r74 r75 1 unit UPool; 2 3 {$mode Delphi}{$H+} 1 unit Pool; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, syncobjs, SpecializedList, UThreading;6 Classes, SysUtils, syncobjs, Generics.Collections, Threading; 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, ''); … … 201 199 202 200 end. 203 -
trunk/Packages/Common/PrefixMultiplier.pas
r74 r75 1 unit UPrefixMultiplier;1 unit PrefixMultiplier; 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; … … 33 31 ( 34 32 (ShortText: 'y'; FullText: 'yocto'; Value: 1e-24), 35 33 (ShortText: 'z'; FullText: 'zepto'; Value: 1e-21), 36 34 (ShortText: 'a'; FullText: 'atto'; Value: 1e-18), 37 35 (ShortText: 'f'; FullText: 'femto'; Value: 1e-15), … … 54 52 ( 55 53 (ShortText: 'ys'; FullText: 'yocto'; Value: 1e-24), 56 54 (ShortText: 'zs'; FullText: 'zepto'; Value: 1e-21), 57 55 (ShortText: 'as'; FullText: 'atto'; Value: 1e-18), 58 56 (ShortText: 'fs'; FullText: 'femto'; Value: 1e-15), … … 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; … … 118 124 119 125 end. 120 -
trunk/Packages/Common/RegistryEx.pas
r74 r75 1 unit URegistry; 2 3 {$MODE Delphi} 1 unit RegistryEx; 4 2 5 3 interface … … 9 7 10 8 type 11 TRegistryRoot = (rrKeyClassesRoot = HKEY($80000000), 12 rrKeyCurrentUser = HKEY($80000001), 13 rrKeyLocalMachine = HKEY($80000002), 14 rrKeyUsers = HKEY($80000003), 15 rrKeyPerformanceData = HKEY($80000004), 16 rrKeyCurrentConfig = HKEY($80000005), 17 rrKeyDynData = HKEY($80000006)); 9 TRegistryRoot = (rrKeyClassesRoot, rrKeyCurrentUser, rrKeyLocalMachine, 10 rrKeyUsers, rrKeyPerformanceData, rrKeyCurrentConfig, rrKeyDynData); 18 11 19 12 { TRegistryContext } … … 22 15 RootKey: HKEY; 23 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; 24 19 class operator Equal(A, B: TRegistryContext): Boolean; 25 20 end; … … 32 27 procedure SetCurrentContext(AValue: TRegistryContext); 33 28 public 29 function ReadChar(const Name: string): Char; 30 procedure WriteChar(const Name: string; Value: Char); 34 31 function ReadBoolWithDefault(const Name: string; 35 32 DefaultValue: Boolean): Boolean; 36 33 function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer; 37 34 function ReadStringWithDefault(const Name: string; DefaultValue: string): string; 35 function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char; 38 36 function ReadFloatWithDefault(const Name: string; 39 37 DefaultValue: Double): Double; … … 43 41 end; 44 42 45 function RegContext(RootKey: HKEY; Key: string): TRegistryContext; 43 const 44 RegistryRootHKEY: array[TRegistryRoot] of HKEY = (HKEY_CLASSES_ROOT, 45 HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, 46 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 46 47 47 48 48 49 implementation 49 50 function RegContext(RootKey: HKEY; Key: string): TRegistryContext;51 begin52 Result.RootKey := RootKey;53 Result.Key := Key;54 end;55 50 56 51 { TRegistryContext } … … 59 54 begin 60 55 Result := (A.Key = B.Key) and (A.RootKey = B.RootKey); 56 end; 57 58 class function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 59 begin 60 Result.RootKey := RegistryRootHKEY[RootKey]; 61 Result.Key := Key; 62 end; 63 64 class function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 65 begin 66 Result.RootKey := RootKey; 67 Result.Key := Key; 61 68 end; 62 69 … … 79 86 else begin 80 87 WriteString(Name, DefaultValue); 88 Result := DefaultValue; 89 end; 90 end; 91 92 function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char 93 ): Char; 94 begin 95 if ValueExists(Name) then Result := ReadChar(Name) 96 else begin 97 WriteChar(Name, DefaultValue); 81 98 Result := DefaultValue; 82 99 end; … … 113 130 function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean; 114 131 begin 115 {$IFDEF Linux}116 CloseKey;132 {$IFDEF UNIX} 133 //CloseKey; 117 134 {$ENDIF} 118 135 Result := inherited OpenKey(Key, CanCreate); … … 121 138 function TRegistryEx.GetCurrentContext: TRegistryContext; 122 139 begin 123 Result.Key := CurrentPath;140 Result.Key := String(CurrentPath); 124 141 Result.RootKey := RootKey; 125 142 end; … … 129 146 RootKey := AValue.RootKey; 130 147 OpenKey(AValue.Key, True); 148 end; 149 150 function TRegistryEx.ReadChar(const Name: string): Char; 151 var 152 S: string; 153 begin 154 S := ReadString(Name); 155 if Length(S) > 0 then Result := S[1] 156 else Result := #0; 157 end; 158 159 procedure TRegistryEx.WriteChar(const Name: string; Value: Char); 160 begin 161 WriteString(Name, Value); 131 162 end; 132 163 -
trunk/Packages/Common/ResetableThread.pas
r74 r75 1 unit UResetableThread; 2 3 {$mode Delphi}{$H+} 1 unit ResetableThread; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, syncobjs, UThreading, UPool;6 Classes, SysUtils, syncobjs, Threading, Pool; 9 7 10 8 type … … 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 298 296 end. 299 -
trunk/Packages/Common/StopWatch.pas
r73 r75 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/SyncCounter.pas
r74 r75 1 unit USyncCounter; 2 3 {$mode delphi} 1 unit SyncCounter; 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 … … 79 78 80 79 end. 81 -
trunk/Packages/Common/Threading.pas
r74 r75 1 unit UThreading; 2 3 {$mode delphi} 1 unit Threading; 4 2 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 … … 378 366 379 367 end. 380 -
trunk/Packages/Common/URI.pas
r74 r75 1 unit U URI;1 unit URI; 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. 354 -
trunk/Packages/Common/XML.pas
r74 r75 1 unit UXMLUtils; 2 3 {$mode delphi} 1 unit XML; 4 2 5 3 interface … … 7 5 uses 8 6 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils ;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; 11 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 12 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 13 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 14 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 15 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 16 procedure WriteDouble(Node: TDOMNode; Name: string; Value: Double); 17 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 18 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 19 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 20 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 21 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 22 function ReadDouble(Node: TDOMNode; Name: string; DefaultValue: Double): Double; 23 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 13 24 14 25 15 26 implementation 27 28 function ReadDouble(Node: TDOMNode; Name: string; DefaultValue: Double): Double; 29 var 30 NewNode: TDOMNode; 31 begin 32 Result := DefaultValue; 33 NewNode := Node.FindNode(DOMString(Name)); 34 if Assigned(NewNode) then 35 Result := StrToFloat(string(NewNode.TextContent)); 36 end; 37 38 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 39 var 40 Parser: TDOMParser; 41 Src: TXMLInputSource; 42 InFile: TFileStream; 43 begin 44 try 45 InFile := TFileStream.Create(FileName, fmOpenRead); 46 Src := TXMLInputSource.Create(InFile); 47 Parser := TDOMParser.Create; 48 Parser.Options.PreserveWhitespace := True; 49 Parser.Parse(Src, Doc); 50 finally 51 Src.Free; 52 Parser.Free; 53 InFile.Free; 54 end; 55 end; 16 56 17 57 function GetTimeZoneBias: Integer; … … 20 60 TimeZoneInfo: TTimeZoneInformation; 21 61 begin 62 {$push}{$warn 5057 off} 22 63 case GetTimeZoneInformation(TimeZoneInfo) of 23 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;24 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;64 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 65 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 25 66 else 26 67 Result := 0; 27 68 end; 69 {$pop} 28 70 end; 29 71 {$ELSE} … … 35 77 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 36 78 var 37 I , J: Integer;79 I: Integer; 38 80 Matched: Boolean; 39 81 begin … … 66 108 Minute: Integer; 67 109 Second: Integer; 110 SecondFraction: Double; 68 111 Millisecond: Integer; 69 112 begin … … 88 131 if Pos('Z', XMLDateTime) > 0 then 89 132 LeftCutString(XMLDateTime, Part, 'Z'); 90 Millisecond := StrToInt(Part); 133 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 134 Millisecond := Trunc(SecondFraction * 1000); 91 135 end else begin 92 136 if Pos('+', XMLDateTime) > 0 then … … 106 150 end; 107 151 108 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;152 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 109 153 const 110 154 Neg: array[Boolean] of string = ('+', '-'); … … 123 167 end; 124 168 169 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 170 var 171 NewNode: TDOMNode; 172 begin 173 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 174 NewNode.TextContent := DOMString(IntToStr(Value)); 175 Node.AppendChild(NewNode); 176 end; 177 178 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 179 var 180 NewNode: TDOMNode; 181 begin 182 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 183 NewNode.TextContent := DOMString(IntToStr(Value)); 184 Node.AppendChild(NewNode); 185 end; 186 187 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 188 var 189 NewNode: TDOMNode; 190 begin 191 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 192 NewNode.TextContent := DOMString(BoolToStr(Value)); 193 Node.AppendChild(NewNode); 194 end; 195 196 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 197 var 198 NewNode: TDOMNode; 199 begin 200 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 201 NewNode.TextContent := DOMString(Value); 202 Node.AppendChild(NewNode); 203 end; 204 205 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 206 var 207 NewNode: TDOMNode; 208 begin 209 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 210 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 211 Node.AppendChild(NewNode); 212 end; 213 214 procedure WriteDouble(Node: TDOMNode; Name: string; Value: Double); 215 var 216 NewNode: TDOMNode; 217 begin 218 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 219 NewNode.TextContent := DOMString(FloatToStr(Value)); 220 Node.AppendChild(NewNode); 221 end; 222 223 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 224 var 225 NewNode: TDOMNode; 226 begin 227 Result := DefaultValue; 228 NewNode := Node.FindNode(DOMString(Name)); 229 if Assigned(NewNode) then 230 Result := StrToInt(string(NewNode.TextContent)); 231 end; 232 233 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 234 var 235 NewNode: TDOMNode; 236 begin 237 Result := DefaultValue; 238 NewNode := Node.FindNode(DOMString(Name)); 239 if Assigned(NewNode) then 240 Result := StrToInt64(string(NewNode.TextContent)); 241 end; 242 243 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 244 var 245 NewNode: TDOMNode; 246 begin 247 Result := DefaultValue; 248 NewNode := Node.FindNode(DOMString(Name)); 249 if Assigned(NewNode) then 250 Result := StrToBool(string(NewNode.TextContent)); 251 end; 252 253 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 254 var 255 NewNode: TDOMNode; 256 begin 257 Result := DefaultValue; 258 NewNode := Node.FindNode(DOMString(Name)); 259 if Assigned(NewNode) then 260 Result := string(NewNode.TextContent); 261 end; 262 263 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime 264 ): TDateTime; 265 var 266 NewNode: TDOMNode; 267 begin 268 Result := DefaultValue; 269 NewNode := Node.FindNode(DOMString(Name)); 270 if Assigned(NewNode) then 271 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 272 end; 273 125 274 end. 126
Note:
See TracChangeset
for help on using the changeset viewer.