Changeset 122 for trunk/Packages
- Timestamp:
- Jun 29, 2018, 11:44:07 PM (6 years ago)
- Location:
- trunk/Packages
- Files:
-
- 8 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Common.lpk
r89 r122 1 <?xml version="1.0" ?>1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <CONFIG> 3 3 <Package Version="4"> 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 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(BuildMode)"/> 13 14 </SearchPaths> 15 <Parsing> 16 <SyntaxOptions> 17 <SyntaxMode Value="Delphi"/> 18 <CStyleOperator Value="False"/> 19 <AllowLabel Value="False"/> 20 <CPPInline Value="False"/> 21 </SyntaxOptions> 22 </Parsing> 23 <CodeGeneration> 24 <Optimizations> 25 <OptimizationLevel Value="0"/> 26 </Optimizations> 27 </CodeGeneration> 28 <Linking> 29 <Debugging> 30 <GenerateDebugInfo Value="False"/> 31 </Debugging> 32 </Linking> 14 33 <Other> 15 34 <CompilerMessages> 16 < UseMsgFile Value="True"/>35 <IgnoredMessages idx5024="True"/> 17 36 </CompilerMessages> 18 <CompilerPath Value="$(CompPath)"/>19 37 </Other> 20 38 </CompilerOptions> … … 22 40 <License Value="GNU/GPL"/> 23 41 <Version Minor="7"/> 24 <Files Count=" 15">42 <Files Count="22"> 25 43 <Item1> 26 44 <Filename Value="StopWatch.pas"/> … … 87 105 <UnitName Value="UApplicationInfo"/> 88 106 </Item15> 107 <Item16> 108 <Filename Value="USyncCounter.pas"/> 109 <UnitName Value="USyncCounter"/> 110 </Item16> 111 <Item17> 112 <Filename Value="UListViewSort.pas"/> 113 <HasRegisterProc Value="True"/> 114 <UnitName Value="UListViewSort"/> 115 </Item17> 116 <Item18> 117 <Filename Value="UPersistentForm.pas"/> 118 <HasRegisterProc Value="True"/> 119 <UnitName Value="UPersistentForm"/> 120 </Item18> 121 <Item19> 122 <Filename Value="UFindFile.pas"/> 123 <HasRegisterProc Value="True"/> 124 <UnitName Value="UFindFile"/> 125 </Item19> 126 <Item20> 127 <Filename Value="UScaleDPI.pas"/> 128 <HasRegisterProc Value="True"/> 129 <UnitName Value="UScaleDPI"/> 130 </Item20> 131 <Item21> 132 <Filename Value="UTheme.pas"/> 133 <HasRegisterProc Value="True"/> 134 <UnitName Value="UTheme"/> 135 </Item21> 136 <Item22> 137 <Filename Value="UStringTable.pas"/> 138 <UnitName Value="UStringTable"/> 139 </Item22> 89 140 </Files> 90 141 <i18n> 91 142 <EnableI18N Value="True"/> 92 143 <OutDir Value="Languages"/> 144 <EnableI18NForLFM Value="True"/> 93 145 </i18n> 94 <Type Value="RunAndDesignTime"/> 95 <RequiredPkgs Count="2"> 146 <RequiredPkgs Count="3"> 96 147 <Item1> 97 <PackageName Value=" TemplateGenerics"/>148 <PackageName Value="LCL"/> 98 149 </Item1> 99 150 <Item2> 151 <PackageName Value="TemplateGenerics"/> 152 </Item2> 153 <Item3> 100 154 <PackageName Value="FCL"/> 101 155 <MinVersion Major="1" Valid="True"/> 102 </Item 2>156 </Item3> 103 157 </RequiredPkgs> 104 158 <UsageOptions> -
trunk/Packages/Common/Common.pas
r89 r122 5 5 unit Common; 6 6 7 {$warn 5023 off : no warning about unused units} 7 8 interface 8 9 … … 10 11 StopWatch, UCommon, UDebugLog, UDelay, UPrefixMultiplier, UURI, UThreading, 11 12 UMemory, UResetableThread, UPool, ULastOpenedList, URegistry, 12 UJobProgressView, UXMLUtils, UApplicationInfo, LazarusPackageIntf; 13 UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort, 14 UPersistentForm, UFindFile, UScaleDPI, UTheme, UStringTable, 15 LazarusPackageIntf; 13 16 14 17 implementation … … 20 23 RegisterUnit('UJobProgressView', @UJobProgressView.Register); 21 24 RegisterUnit('UApplicationInfo', @UApplicationInfo.Register); 25 RegisterUnit('UListViewSort', @UListViewSort.Register); 26 RegisterUnit('UPersistentForm', @UPersistentForm.Register); 27 RegisterUnit('UFindFile', @UFindFile.Register); 28 RegisterUnit('UScaleDPI', @UScaleDPI.Register); 29 RegisterUnit('UTheme', @UTheme.Register); 22 30 end; 23 31 -
trunk/Packages/Common/Languages/UJobProgressView.po
r89 r122 14 14 msgstr "" 15 15 16 #: ujobprogressview.soperations 17 msgid "Operations:" 18 msgstr "" 19 16 20 #: ujobprogressview.spleasewait 17 21 msgid "Please wait..." -
trunk/Packages/Common/UApplicationInfo.pas
r89 r122 6 6 7 7 uses 8 SysUtils, Registry, Classes, Forms, URegistry;8 SysUtils, Classes, Forms, URegistry, Controls; 9 9 10 10 type … … 14 14 TApplicationInfo = class(TComponent) 15 15 private 16 FDescription: TCaption; 16 17 FIdentification: Byte; 18 FLicense: string; 17 19 FVersionMajor: Byte; 18 20 FVersionMinor: Byte; … … 32 34 constructor Create(AOwner: TComponent); 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: string 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; 49 54 end; 50 55 … … 52 57 53 58 implementation 54 59 55 60 procedure Register; 56 61 begin 57 RegisterComponents(' Samples', [TApplicationInfo]);62 RegisterComponents('Common', [TApplicationInfo]); 58 63 end; 59 64 … … 77 82 end; 78 83 84 function TApplicationInfo.GetRegistryContext: TRegistryContext; 85 begin 86 Result := TRegistryContext.Create(RegistryRoot, RegistryKey); 87 end; 88 79 89 end. -
trunk/Packages/Common/UCommon.pas
r114 r122 6 6 7 7 uses 8 {$IFDEF Windows}Windows,{$ENDIF} 9 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, LazFileUtils, 8 {$ifdef Windows}Windows,{$endif} 9 {$ifdef Linux}baseunix,{$endif} 10 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 10 11 FileUtil; //, ShFolder, ShellAPI; 11 12 … … 27 28 unfDNSDomainName = 11); 28 29 30 TFilterMethodMethod = function (FileName: string): Boolean of object; 29 31 var 30 32 ExceptionHandler: TExceptionEvent; … … 48 50 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 49 51 function SplitString(var Text: string; Count: Word): string; 52 function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer; 50 53 function GetBit(Variable: QWord; Index: Byte): Boolean; 54 procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean); overload; 51 55 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload; 52 56 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload; … … 60 64 procedure OpenWebPage(URL: string); 61 65 procedure OpenFileInShell(FileName: string); 62 procedure ExecuteProgram( CommandLine:string);66 procedure ExecuteProgram(Executable: string; Parameters: array of string); 63 67 procedure FreeThenNil(var Obj); 68 function RemoveQuotes(Text: string): string; 69 function ComputerName: string; 70 function OccurenceOfChar(What: Char; Where: string): Integer; 71 function GetDirCount(Dir: string): Integer; 72 function MergeArray(A, B: array of string): TArrayOfString; 73 function LoadFileToStr(const FileName: TFileName): AnsiString; 74 procedure SearchFiles(AList: TStrings; Dir: string; 75 FilterMethod: TFilterMethodMethod = nil); 76 function GetStringPart(var Text: string; Separator: string): string; 64 77 65 78 … … 103 116 Path := IncludeTrailingPathDelimiter(APath); 104 117 105 Find := FindFirst( UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);118 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 106 119 while Find = 0 do begin 107 DeleteFile UTF8(Path + UTF8Encode(SearchRec.Name));120 DeleteFile(Path + SearchRec.Name); 108 121 109 122 Find := SysUtils.FindNext(SearchRec); … … 284 297 L: LongWord; 285 298 begin 286 287 299 L := MAX_USERNAME_LENGTH + 2; 288 300 SetLength(Result, L); … … 299 311 end; 300 312 end; 301 313 {$endif} 314 315 function ComputerName: string; 316 {$ifdef mswindows} 317 const 318 INFO_BUFFER_SIZE = 32767; 319 var 320 Buffer : array[0..INFO_BUFFER_SIZE] of WideChar; 321 Ret : DWORD; 322 begin 323 Ret := INFO_BUFFER_SIZE; 324 If (GetComputerNameW(@Buffer[0],Ret)) then begin 325 Result := UTF8Encode(WideString(Buffer)); 326 end 327 else begin 328 Result := 'ERROR_NO_COMPUTERNAME_RETURNED'; 329 end; 330 end; 331 {$endif} 332 {$ifdef unix} 333 var 334 Name: UtsName; 335 begin 336 fpuname(Name); 337 Result := Name.Nodename; 338 end; 339 {$endif} 340 341 {$ifdef windows} 302 342 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 303 343 const … … 336 376 end; 337 377 378 function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer; 379 var 380 I: Integer; 381 begin 382 Result := 0; 383 for I := 0 to MaxIndex - 1 do 384 if ((Variable shr I) and 1) = 1 then Inc(Result); 385 end; 386 338 387 function GetBit(Variable:QWord;Index:Byte):Boolean; 339 388 begin … … 341 390 end; 342 391 392 procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean); 393 begin 394 Variable := (Variable and ((1 shl Index) xor High(QWord))) or (Int64(State) shl Index); 395 end; 396 343 397 procedure SetBit(var Variable:QWord;Index:Byte;State:Boolean); overload; 344 398 begin 345 Variable := (Variable and ((1 shl Index) xor QWord($ffffffffffffffff))) or (QWord(State) shl Index);399 Variable := (Variable and ((1 shl Index) xor High(QWord))) or (QWord(State) shl Index); 346 400 end; 347 401 348 402 procedure SetBit(var Variable:Cardinal;Index:Byte;State:Boolean); overload; 349 403 begin 350 Variable := (Variable and ((1 shl Index) xor Cardinal($ffffffff))) or (Cardinal(State) shl Index);404 Variable := (Variable and ((1 shl Index) xor High(Cardinal))) or (Cardinal(State) shl Index); 351 405 end; 352 406 353 407 procedure SetBit(var Variable:Word;Index:Byte;State:Boolean); overload; 354 408 begin 355 Variable := (Variable and ((1 shl Index) xor Word($ffff))) or (Word(State) shl Index);409 Variable := (Variable and ((1 shl Index) xor High(Word))) or (Word(State) shl Index); 356 410 end; 357 411 … … 379 433 end; 380 434 381 procedure ExecuteProgram( CommandLine:string);435 procedure ExecuteProgram(Executable: string; Parameters: array of string); 382 436 var 383 437 Process: TProcess; 438 I: Integer; 384 439 begin 385 440 try 386 441 Process := TProcess.Create(nil); 387 Process.CommandLine := CommandLine; 442 Process.Executable := Executable; 443 for I := 0 to Length(Parameters) - 1 do 444 Process.Parameters.Add(Parameters[I]); 388 445 Process.Options := [poNoConsole]; 389 446 Process.Execute; … … 400 457 401 458 procedure OpenWebPage(URL: string); 402 var403 Process: TProcess;404 Browser, Params: string;405 459 begin 406 460 OpenURL(URL); 407 {try 408 Process := TProcess.Create(nil); 409 Browser := ''; 410 //FindDefaultBrowser(Browser, Params); 411 //Process.Executable := Browser; 412 //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]); 413 Process.CommandLine := 'cmd.exe /c start ' + URL; 414 Process.Options := [poNoConsole]; 415 Process.Execute; 461 end; 462 463 procedure OpenFileInShell(FileName: string); 464 begin 465 ExecuteProgram('cmd.exe', ['/c', 'start', FileName]); 466 end; 467 468 function RemoveQuotes(Text: string): string; 469 begin 470 Result := Text; 471 if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then 472 Result := Copy(Text, 2, Length(Text) - 2); 473 end; 474 475 function OccurenceOfChar(What: Char; Where: string): Integer; 476 var 477 I: Integer; 478 begin 479 Result := 0; 480 for I := 1 to Length(Where) do 481 if Where[I] = What then Inc(Result); 482 end; 483 484 function GetDirCount(Dir: string): Integer; 485 begin 486 Result := OccurenceOfChar(DirectorySeparator, Dir); 487 if Copy(Dir, Length(Dir), 1) = DirectorySeparator then 488 Dec(Result); 489 end; 490 491 function MergeArray(A, B: array of string): TArrayOfString; 492 var 493 I: Integer; 494 begin 495 SetLength(Result, Length(A) + Length(B)); 496 for I := 0 to Length(A) - 1 do 497 Result[I] := A[I]; 498 for I := 0 to Length(B) - 1 do 499 Result[Length(A) + I] := B[I]; 500 end; 501 502 function LoadFileToStr(const FileName: TFileName): AnsiString; 503 var 504 FileStream: TFileStream; 505 Read: Integer; 506 begin 507 Result := ''; 508 FileStream := TFileStream.Create(FileName, fmOpenRead); 509 try 510 if FileStream.Size > 0 then begin 511 SetLength(Result, FileStream.Size); 512 Read := FileStream.Read(Pointer(Result)^, FileStream.Size); 513 SetLength(Result, Read); 514 end; 416 515 finally 417 Process.Free; 418 end;} 419 end; 420 421 procedure OpenFileInShell(FileName: string); 422 begin 423 ExecuteProgram('cmd.exe /c start "' + FileName + '"'); 424 end; 516 FileStream.Free; 517 end; 518 end; 519 520 function DefaultSearchFilter(const FileName: string): Boolean; 521 begin 522 Result := True; 523 end; 524 525 procedure SearchFiles(AList: TStrings; Dir: string; 526 FilterMethod: TFilterMethodMethod = nil); 527 var 528 SR: TSearchRec; 529 begin 530 Dir := IncludeTrailingPathDelimiter(Dir); 531 if FindFirst(Dir + '*', faAnyFile, SR) = 0 then 532 try 533 repeat 534 if (SR.Name = '.') or (SR.Name = '..') or (Assigned(FilterMethod) and (not FilterMethod(SR.Name) or 535 not FilterMethod(Copy(Dir, 3, Length(Dir)) + SR.Name))) then Continue; 536 AList.Add(Dir + SR.Name); 537 if (SR.Attr and faDirectory) <> 0 then 538 SearchFiles(AList, Dir + SR.Name, FilterMethod); 539 until FindNext(SR) <> 0; 540 finally 541 FindClose(SR); 542 end; 543 end; 544 545 function GetStringPart(var Text: string; Separator: string): string; 546 var 547 P: Integer; 548 begin 549 P := Pos(Separator, Text); 550 if P > 0 then begin 551 Result := Copy(Text, 1, P - 1); 552 Delete(Text, 1, P - 1 + Length(Separator)); 553 end else begin 554 Result := Text; 555 Text := ''; 556 end; 557 Result := Trim(Result); 558 Text := Trim(Text); 559 end; 560 561 425 562 426 563 initialization -
trunk/Packages/Common/UDebugLog.pas
r114 r122 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, SpecializedList, SyncObjs , LazFileUtils;8 Classes, SysUtils, FileUtil, SpecializedList, SyncObjs; 9 9 10 10 type … … 31 31 Items: TListObject; 32 32 Lock: TCriticalSection; 33 procedure Add( Group: string; Text: string);33 procedure Add(Text: string; Group: string = ''); 34 34 procedure WriteToFile(Text: string); 35 35 constructor Create(AOwner: TComponent); override; … … 52 52 procedure Register; 53 53 begin 54 RegisterComponents(' Samples', [TDebugLog]);54 RegisterComponents('Common', [TDebugLog]); 55 55 end; 56 56 … … 69 69 end; 70 70 71 procedure TDebugLog.Add( Group: string; Text: string);71 procedure TDebugLog.Add(Text: string; Group: string = ''); 72 72 var 73 73 NewItem: TDebugLogItem; … … 103 103 try 104 104 if ExtractFileDir(FileName) <> '' then 105 ForceDirectories UTF8(ExtractFileDir(FileName));106 if FileExists UTF8(FileName) then LogFile := TFileStream.Create(UTF8Decode(FileName), fmOpenWrite)107 else LogFile := TFileStream.Create( UTF8Decode(FileName), fmCreate);105 ForceDirectories(ExtractFileDir(FileName)); 106 if FileExists(FileName) then LogFile := TFileStream.Create(FileName, fmOpenWrite) 107 else LogFile := TFileStream.Create(FileName, fmCreate); 108 108 LogFile.Seek(0, soFromEnd); 109 109 Text := FormatDateTime('hh:nn:ss.zzz', Now) + ': ' + Text + LineEnding; -
trunk/Packages/Common/UFindFile.pas
r84 r122 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 … … 55 55 end; 56 56 57 const 58 {$IFDEF WINDOWS} 59 FilterAll = '*.*'; 60 {$ENDIF} 61 {$IFDEF LINUX} 62 FilterAll = '*'; 63 {$ENDIF} 64 57 65 procedure Register; 58 66 … … 64 72 procedure Register; 65 73 begin 66 RegisterComponents(' Samples', [TFindFile]);74 RegisterComponents('Common', [TFindFile]); 67 75 end; 68 76 … … 71 79 inherited Create(AOwner); 72 80 Path := IncludeTrailingBackslash(UTF8Encode(GetCurrentDir)); 73 FileMask := '*.*';81 FileMask := FilterAll; 74 82 FileAttr := [ffaAnyFile]; 75 83 s := TStringList.Create; … … 109 117 Attr := 0; 110 118 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;119 if ffaHidden in FileAttr then Attr := Attr + 2; //faHidden; use constant to avoid platform warning 120 if ffaSysFile in FileAttr then Attr := Attr + 4; //faSysFile; use constant to avoid platform warning 121 // Deprecated: if ffaVolumeID in FileAttr then Attr := Attr + faVolumeID; 114 122 if ffaDirectory in FileAttr then Attr := Attr + faDirectory; 115 123 if ffaArchive in FileAttr then Attr := Attr + faArchive; 116 124 if ffaAnyFile in FileAttr then Attr := Attr + faAnyFile; 117 125 118 if SysUtils.FindFirst( UTF8Decode(inPath + FileMask), Attr, Rec) = 0 then126 if SysUtils.FindFirst(inPath + FileMask, Attr, Rec) = 0 then 119 127 try 120 128 repeat 121 s.Add(inPath + UTF8Encode(Rec.Name));129 s.Add(inPath + Rec.Name); 122 130 until SysUtils.FindNext(Rec) <> 0; 123 131 finally … … 127 135 If not InSubFolders then Exit; 128 136 129 if SysUtils.FindFirst( UTF8Decode(inPath + '*.*'), faDirectory, Rec) = 0 then137 if SysUtils.FindFirst(inPath + FilterAll, faDirectory, Rec) = 0 then 130 138 try 131 139 repeat 132 140 if ((Rec.Attr and faDirectory) > 0) and (Rec.Name <> '.') 133 141 and (Rec.Name <> '..') then 134 FileSearch(IncludeTrailingBackslash(inPath + UTF8Encode(Rec.Name)));142 FileSearch(IncludeTrailingBackslash(inPath + Rec.Name)); 135 143 until SysUtils.FindNext(Rec) <> 0; 136 144 finally -
trunk/Packages/Common/UJobProgressView.lfm
r89 r122 1 1 object FormJobProgressView: TFormJobProgressView 2 2 Left = 467 3 Height = 2463 Height = 345 4 4 Top = 252 5 Width = 3285 Width = 539 6 6 BorderIcons = [biSystemMenu] 7 ClientHeight = 246 8 ClientWidth = 328 9 Font.Height = -11 10 Font.Name = 'MS Sans Serif' 7 ClientHeight = 345 8 ClientWidth = 539 9 DesignTimePPI = 120 11 10 OnClose = FormClose 12 11 OnCloseQuery = FormCloseQuery 13 12 OnCreate = FormCreate 14 13 OnDestroy = FormDestroy 14 OnHide = FormHide 15 OnShow = FormShow 15 16 Position = poScreenCenter 16 LCLVersion = '1. 1'17 LCLVersion = '1.8.2.0' 17 18 object PanelOperationsTitle: TPanel 18 19 Left = 0 19 Height = 2420 Height = 32 20 21 Top = 0 21 Width = 32822 Align = alTop 23 BevelOuter = bvNone 24 ClientHeight = 2425 ClientWidth = 32822 Width = 539 23 Align = alTop 24 BevelOuter = bvNone 25 ClientHeight = 32 26 ClientWidth = 539 26 27 FullRepaint = False 27 28 TabOrder = 0 28 29 object LabelOperation: TLabel 29 30 Left = 8 30 Height = 1431 Height = 20 31 32 Top = 8 32 Width = 6733 Width = 76 33 34 Caption = 'Operations:' 34 Font.Height = -1135 Font.Name = 'MS Sans Serif'36 Font.Style = [fsBold]37 35 ParentColor = False 38 36 ParentFont = False … … 41 39 object PanelLog: TPanel 42 40 Left = 0 43 Height = 1 2244 Top = 12445 Width = 32841 Height = 133 42 Top = 212 43 Width = 539 46 44 Align = alClient 47 45 BevelOuter = bvSpace 48 ClientHeight = 1 2249 ClientWidth = 32846 ClientHeight = 133 47 ClientWidth = 539 50 48 TabOrder = 1 51 49 object MemoLog: TMemo 52 50 Left = 8 53 Height = 1 0651 Height = 117 54 52 Top = 8 55 Width = 31253 Width = 523 56 54 Anchors = [akTop, akLeft, akRight, akBottom] 57 55 ReadOnly = True … … 62 60 object PanelProgress: TPanel 63 61 Left = 0 64 Height = 3865 Top = 5066 Width = 32867 Align = alTop 68 BevelOuter = bvNone 69 ClientHeight = 3870 ClientWidth = 32862 Height = 54 63 Top = 106 64 Width = 539 65 Align = alTop 66 BevelOuter = bvNone 67 ClientHeight = 54 68 ClientWidth = 539 71 69 TabOrder = 2 72 70 object ProgressBarPart: TProgressBar 73 Left = 874 Height = 1775 Top = 1676 Width = 31271 Left = 10 72 Height = 24 73 Top = 24 74 Width = 523 77 75 Anchors = [akTop, akLeft, akRight] 78 76 TabOrder = 0 … … 80 78 object LabelEstimatedTimePart: TLabel 81 79 Left = 8 82 Height = 1480 Height = 20 83 81 Top = -2 84 Width = 7282 Width = 103 85 83 Caption = 'Estimated time:' 86 84 ParentColor = False … … 89 87 object PanelOperations: TPanel 90 88 Left = 0 91 Height = 2692 Top = 2493 Width = 32894 Align = alTop 95 BevelOuter = bvNone 96 ClientHeight = 2697 ClientWidth = 32889 Height = 42 90 Top = 64 91 Width = 539 92 Align = alTop 93 BevelOuter = bvNone 94 ClientHeight = 42 95 ClientWidth = 539 98 96 FullRepaint = False 99 97 TabOrder = 3 100 98 object ListViewJobs: TListView 101 99 Left = 8 102 Height = 16100 Height = 32 103 101 Top = 5 104 Width = 312102 Width = 523 105 103 Anchors = [akTop, akLeft, akRight, akBottom] 106 104 AutoWidthLastColumn = True … … 109 107 Columns = < 110 108 item 111 Width = 312109 Width = 523 112 110 end> 113 111 OwnerData = True … … 122 120 object PanelProgressTotal: TPanel 123 121 Left = 0 124 Height = 36125 Top = 88126 Width = 328127 Align = alTop 128 BevelOuter = bvNone 129 ClientHeight = 36130 ClientWidth = 328122 Height = 52 123 Top = 160 124 Width = 539 125 Align = alTop 126 BevelOuter = bvNone 127 ClientHeight = 52 128 ClientWidth = 539 131 129 TabOrder = 4 132 130 object LabelEstimatedTimeTotal: TLabel 133 131 Left = 8 134 Height = 14132 Height = 20 135 133 Top = 0 136 Width = 98134 Width = 141 137 135 Caption = 'Total estimated time:' 138 136 ParentColor = False … … 140 138 object ProgressBarTotal: TProgressBar 141 139 Left = 8 142 Height = 16143 Top = 16144 Width = 312140 Height = 24 141 Top = 24 142 Width = 523 145 143 Anchors = [akTop, akLeft, akRight] 146 144 TabOrder = 0 145 end 146 end 147 object PanelText: TPanel 148 Left = 0 149 Height = 32 150 Top = 32 151 Width = 539 152 Align = alTop 153 BevelOuter = bvNone 154 ClientHeight = 32 155 ClientWidth = 539 156 TabOrder = 5 157 object LabelText: TLabel 158 Left = 8 159 Height = 24 160 Top = 8 161 Width = 525 162 Anchors = [akTop, akLeft, akRight] 163 AutoSize = False 164 ParentColor = False 147 165 end 148 166 end -
trunk/Packages/Common/UJobProgressView.lrt
r89 r122 1 T JOBPROGRESSVIEW.LABELOPERATION.CAPTION=Operations:2 T JOBPROGRESSVIEW.LABELESTIMATEDTIMEPART.CAPTION=Estimated time:3 T JOBPROGRESSVIEW.LABELESTIMATEDTIMETOTAL.CAPTION=Total estimated time:1 TFORMJOBPROGRESSVIEW.LABELOPERATION.CAPTION=Operations: 2 TFORMJOBPROGRESSVIEW.LABELESTIMATEDTIMEPART.CAPTION=Estimated time: 3 TFORMJOBPROGRESSVIEW.LABELESTIMATEDTIMETOTAL.CAPTION=Total estimated time: -
trunk/Packages/Common/UJobProgressView.pas
r89 r122 7 7 uses 8 8 SysUtils, Variants, Classes, Graphics, Controls, Forms, Syncobjs, 9 Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading, 9 Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading, Math, 10 10 DateUtils; 11 11 … … 13 13 EstimatedTimeShowTreshold = 4; 14 14 EstimatedTimeShowTresholdTotal = 1; 15 MemoLogHeight = 200;16 15 UpdateInterval = 100; // ms 17 16 … … 24 23 FLock: TCriticalSection; 25 24 FOnChange: TNotifyEvent; 25 FText: string; 26 26 FValue: Integer; 27 27 FMax: Integer; 28 28 procedure SetMax(const AValue: Integer); 29 procedure SetText(AValue: string); 29 30 procedure SetValue(const AValue: Integer); 30 31 public … … 35 36 property Value: Integer read FValue write SetValue; 36 37 property Max: Integer read FMax write SetMax; 38 property Text: string read FText write SetText; 37 39 property OnChange: TNotifyEvent read FOnChange write FOnChange; 38 40 end; … … 69 71 end; 70 72 73 TJobs = class(TObjectList) 74 end; 75 71 76 TJobThread = class(TListedThread) 72 77 procedure Execute; override; … … 80 85 TFormJobProgressView = class(TForm) 81 86 ImageList1: TImageList; 87 LabelText: TLabel; 82 88 Label2: TLabel; 83 89 LabelOperation: TLabel; … … 86 92 ListViewJobs: TListView; 87 93 MemoLog: TMemo; 94 PanelText: TPanel; 88 95 PanelProgressTotal: TPanel; 89 96 PanelOperationsTitle: TPanel; … … 94 101 ProgressBarTotal: TProgressBar; 95 102 TimerUpdate: TTimer; 103 procedure FormHide(Sender: TObject); 104 procedure FormShow(Sender: TObject); 105 procedure ReloadJobList; 96 106 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 97 107 procedure FormDestroy(Sender: TObject); … … 100 110 procedure FormCreate(Sender: TObject); 101 111 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 112 procedure UpdateHeight; 102 113 public 103 114 JobProgressView: TJobProgressView; … … 111 122 Finished: Boolean; 112 123 FOnJobFinish: TJobProgressViewMethod; 124 FOnOwnerDraw: TNotifyEvent; 125 FOwnerDraw: Boolean; 113 126 FShowDelay: Integer; 114 127 FTerminate: Boolean; … … 116 129 TotalStartTime: TDateTime; 117 130 Log: TStringList; 118 F orm: TFormJobProgressView;131 FForm: TFormJobProgressView; 119 132 procedure SetTerminate(const AValue: Boolean); 120 133 procedure UpdateProgress; 121 procedure ReloadJobList; 122 procedure StartJobs; 123 procedure UpdateHeight; 134 procedure JobProgressChange(Sender: TObject); 124 135 public 125 Jobs: T ObjectList; // TListObject<TJob>136 Jobs: TJobs; 126 137 CurrentJob: TJob; 127 138 CurrentJobIndex: Integer; … … 129 140 destructor Destroy; override; 130 141 procedure Clear; 131 procedureAddJob(Title: string; Method: TJobProgressViewMethod;132 NoThreaded: Boolean = False; WaitFor: Boolean = False) ;133 procedure Start (AAutoClose: Boolean = True);142 function AddJob(Title: string; Method: TJobProgressViewMethod; 143 NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob; 144 procedure Start; 134 145 procedure Stop; 135 146 procedure TermSleep(Delay: Integer); 147 property Form: TFormJobProgressView read FForm; 136 148 property Terminate: Boolean read FTerminate write SetTerminate; 137 149 published 150 property OwnerDraw: Boolean read FOwnerDraw write FOwnerDraw; 138 151 property ShowDelay: Integer read FShowDelay write FShowDelay; 139 152 property AutoClose: Boolean read FAutoClose write FAutoClose; 140 153 property OnJobFinish: TJobProgressViewMethod read FOnJobFinish 141 154 write FOnJobFinish; 155 property OnOwnerDraw: TNotifyEvent read FOnOwnerDraw 156 write FOnOwnerDraw; 142 157 end; 143 158 … … 160 175 STotalEstimatedTime = 'Total estimated time: %s'; 161 176 SFinished = 'Finished'; 177 SOperations = 'Operations:'; 162 178 163 179 procedure Register; 164 180 begin 165 RegisterComponents('Samples', [TJobProgressView]); 166 end; 181 RegisterComponents('Common', [TJobProgressView]); 182 end; 183 184 { TJobThread } 167 185 168 186 procedure TJobThread.Execute; … … 183 201 end; 184 202 185 procedure TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod; 186 NoThreaded: Boolean = False; WaitFor: Boolean = False); 203 { TFormJobProgressView } 204 205 procedure TFormJobProgressView.UpdateHeight; 187 206 var 188 NewJob: TJob; 189 begin 190 NewJob := TJob.Create; 191 NewJob.ProgressView := Self; 192 NewJob.Title := Title; 193 NewJob.Method := Method; 194 NewJob.NoThreaded := NoThreaded; 195 NewJob.WaitFor := WaitFor; 196 NewJob.Progress.Max := 100; 197 NewJob.Progress.Reset; 198 Jobs.Add(NewJob); 207 H: Integer; 208 PanelOperationsVisible: Boolean; 209 PanelOperationsHeight: Integer; 210 PanelProgressVisible: Boolean; 211 PanelProgressTotalVisible: Boolean; 212 PanelLogVisible: Boolean; 213 MemoLogHeight: Integer = 200; 214 I: Integer; 215 ItemRect: TRect; 216 MaxH: Integer; 217 begin 218 H := PanelOperationsTitle.Height; 219 PanelOperationsVisible := JobProgressView.Jobs.Count > 0; 220 if PanelOperationsVisible <> PanelOperations.Visible then 221 PanelOperations.Visible := PanelOperationsVisible; 222 if ListViewJobs.Items.Count > 0 then begin 223 Maxh := 0; 224 for I := 0 to ListViewJobs.Items.Count - 1 do 225 begin 226 ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds); 227 Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top)); 228 end; 229 PanelOperationsHeight := Scale96ToScreen(12) + Maxh; 230 end else PanelOperationsHeight := Scale96ToScreen(8); 231 if PanelOperationsHeight <> PanelOperations.Height then 232 PanelOperations.Height := PanelOperationsHeight; 233 if PanelOperationsVisible then 234 H := H + PanelOperations.Height; 235 236 PanelProgressVisible := (JobProgressView.Jobs.Count > 0) and not JobProgressView.Finished; 237 if PanelProgressVisible <> PanelProgress.Visible then 238 PanelProgress.Visible := PanelProgressVisible; 239 if PanelProgressVisible then 240 H := H + PanelProgress.Height; 241 PanelProgressTotalVisible := (JobProgressView.Jobs.Count > 1) and not JobProgressView.Finished; 242 if PanelProgressTotalVisible <> PanelProgressTotal.Visible then 243 PanelProgressTotal.Visible := PanelProgressTotalVisible; 244 if PanelProgressTotalVisible then 245 H := H + PanelProgressTotal.Height; 246 Constraints.MinHeight := H; 247 PanelLogVisible := MemoLog.Lines.Count > 0; 248 if PanelLogVisible <> PanelLog.Visible then 249 PanelLog.Visible := PanelLogVisible; 250 if PanelLogVisible then 251 H := H + Scale96ToScreen(MemoLogHeight); 252 if PanelText.Visible then 253 H := H + PanelText.Height; 254 if Height <> H then begin 255 Height := H; 256 Top := (Screen.Height - H) div 2; 257 end; 258 end; 259 260 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject); 261 var 262 ProgressBarPartVisible: Boolean; 263 ProgressBarTotalVisible: Boolean; 264 begin 265 JobProgressView.UpdateProgress; 266 if Visible and (not ProgressBarPart.Visible) and 267 Assigned(JobProgressView.CurrentJob) and 268 (JobProgressView.CurrentJob.Progress.Value > 0) then begin 269 ProgressBarPartVisible := True; 270 if ProgressBarPartVisible <> ProgressBarPart.Visible then 271 ProgressBarPart.Visible := ProgressBarPartVisible; 272 ProgressBarTotalVisible := True; 273 if ProgressBarTotalVisible <> ProgressBarTotal.Visible then 274 ProgressBarTotal.Visible := ProgressBarTotalVisible; 275 end; 276 if not Visible then begin 277 TimerUpdate.Interval := UpdateInterval; 278 if not JobProgressView.OwnerDraw then Show; 279 end; 280 if Assigned(JobProgressView.CurrentJob) then begin 281 LabelText.Caption := JobProgressView.CurrentJob.Progress.Text; 282 if LabelText.Caption <> '' then begin 283 PanelText.Visible := True; 284 UpdateHeight; 285 end; 286 end; 287 end; 288 289 procedure TFormJobProgressView.FormDestroy(Sender:TObject); 290 begin 291 end; 292 293 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem); 294 begin 295 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then 296 with TJob(JobProgressView.Jobs[Item.Index]) do begin 297 Item.Caption := Title; 298 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1 299 else if Finished then Item.ImageIndex := 0 300 else Item.ImageIndex := 2; 301 Item.Data := JobProgressView.Jobs[Item.Index]; 302 end; 303 end; 304 305 procedure TFormJobProgressView.FormClose(Sender: TObject; 306 var CloseAction: TCloseAction); 307 begin 308 end; 309 310 procedure TFormJobProgressView.FormCreate(Sender: TObject); 311 begin 312 Caption := SPleaseWait; 313 try 314 //Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) + 315 // DirectorySeparator + 'horse.avi'; 316 //Animate1.Active := True; 317 except 318 319 end; 320 end; 321 322 procedure TFormJobProgressView.ReloadJobList; 323 begin 324 // Workaround for not showing first line 325 //Form.ListViewJobs.Items.Count := Jobs.Count + 1; 326 //Form.ListViewJobs.Refresh; 327 328 if ListViewJobs.Items.Count <> JobProgressView.Jobs.Count then 329 ListViewJobs.Items.Count := JobProgressView.Jobs.Count; 330 ListViewJobs.Refresh; 331 Application.ProcessMessages; 332 UpdateHeight; 333 end; 334 335 procedure TFormJobProgressView.FormShow(Sender: TObject); 336 begin 337 ReloadJobList; 338 end; 339 340 procedure TFormJobProgressView.FormHide(Sender: TObject); 341 begin 342 JobProgressView.Jobs.Clear; 343 ReloadJobList; 344 end; 345 346 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 347 begin 348 CanClose := JobProgressView.Finished; 349 JobProgressView.Terminate := True; 350 Caption := SPleaseWait + STerminate; 351 end; 352 353 354 { TJobProgressView } 355 356 function TJobProgressView.AddJob(Title: string; Method: TJobProgressViewMethod; 357 NoThreaded: Boolean = False; WaitFor: Boolean = False): TJob; 358 begin 359 Result := TJob.Create; 360 Result.ProgressView := Self; 361 Result.Title := Title; 362 Result.Method := Method; 363 Result.NoThreaded := NoThreaded; 364 Result.WaitFor := WaitFor; 365 Result.Progress.Max := 100; 366 Result.Progress.Reset; 367 Result.Progress.OnChange := JobProgressChange; 368 Jobs.Add(Result); 199 369 //ReloadJobList; 200 370 end; 201 371 202 procedure TJobProgressView.Start(AAutoClose: Boolean = True); 203 begin 204 AutoClose := AAutoClose; 205 StartJobs; 206 end; 207 208 procedure TJobProgressView.StartJobs; 372 procedure TJobProgressView.Start; 209 373 var 210 374 I: Integer; … … 212 376 Terminate := False; 213 377 214 Form.BringToFront;378 if not OwnerDraw then Form.BringToFront; 215 379 216 380 Finished := False; … … 221 385 Form.MemoLog.Clear; 222 386 387 Form.PanelText.Visible := False; 223 388 Form.LabelEstimatedTimePart.Visible := False; 224 389 Form.LabelEstimatedTimeTotal.Visible := False; … … 244 409 CurrentJobIndex := I; 245 410 CurrentJob := TJob(Jobs[I]); 411 JobProgressChange(Self); 246 412 StartTime := Now; 247 413 Form.LabelEstimatedTimePart.Caption := Format(SEstimatedTime, ['']); … … 249 415 Form.ProgressBarPart.Visible := False; 250 416 //Show; 251 ReloadJobList;417 Form.ReloadJobList; 252 418 Application.ProcessMessages; 253 419 if NoThreaded then begin … … 287 453 //if Visible then Hide; 288 454 Form.MemoLog.Lines.Assign(Log); 289 if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin455 if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin 290 456 Form.Hide; 291 457 end; 292 Clear;458 if not Form.Visible then Clear; 293 459 Form.Caption := SFinished; 294 460 //LabelEstimatedTimePart.Visible := False; 295 461 Finished := True; 296 462 CurrentJobIndex := -1; 297 ReloadJobList; 298 end; 299 end; 300 301 procedure TJobProgressView.UpdateHeight; 302 var 303 H: Integer; 304 PanelOperationsVisible: Boolean; 305 PanelOperationsHeight: Integer; 306 PanelProgressVisible: Boolean; 307 PanelProgressTotalVisible: Boolean; 308 PanelLogVisible: Boolean; 309 begin 310 with Form do begin 311 H := PanelOperationsTitle.Height; 312 PanelOperationsVisible := Jobs.Count > 0; 313 if PanelOperationsVisible <> PanelOperations.Visible then 314 PanelOperations.Visible := PanelOperationsVisible; 315 PanelOperationsHeight := 8 + 18 * Jobs.Count; 316 if PanelOperationsHeight <> PanelOperations.Height then 317 PanelOperations.Height := PanelOperationsHeight; 318 if PanelOperationsVisible then 319 H := H + PanelOperations.Height; 320 321 PanelProgressVisible := (Jobs.Count > 0) and not Finished; 322 if PanelProgressVisible <> PanelProgress.Visible then 323 PanelProgress.Visible := PanelProgressVisible; 324 if PanelProgressVisible then 325 H := H + PanelProgress.Height; 326 PanelProgressTotalVisible := (Jobs.Count > 1) and not Finished; 327 if PanelProgressTotalVisible <> PanelProgressTotal.Visible then 328 PanelProgressTotal.Visible := PanelProgressTotalVisible; 329 if PanelProgressTotalVisible then 330 H := H + PanelProgressTotal.Height; 331 Constraints.MinHeight := H; 332 PanelLogVisible := MemoLog.Lines.Count > 0; 333 if PanelLogVisible <> PanelLog.Visible then 334 PanelLog.Visible := PanelLogVisible; 335 if PanelLogVisible then 336 H := H + MemoLogHeight; 337 if Height <> H then Height := H; 338 end; 339 end; 340 341 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject); 342 var 343 ProgressBarPartVisible: Boolean; 344 ProgressBarTotalVisible: Boolean; 345 begin 346 JobProgressView.UpdateProgress; 347 if Visible and (not ProgressBarPart.Visible) and 348 Assigned(JobProgressView.CurrentJob) and 349 (JobProgressView.CurrentJob.Progress.Value > 0) then begin 350 ProgressBarPartVisible := True; 351 if ProgressBarPartVisible <> ProgressBarPart.Visible then 352 ProgressBarPart.Visible := ProgressBarPartVisible; 353 ProgressBarTotalVisible := True; 354 if ProgressBarTotalVisible <> ProgressBarTotal.Visible then 355 ProgressBarTotal.Visible := ProgressBarTotalVisible; 356 end; 357 if not Visible then begin 358 TimerUpdate.Interval := UpdateInterval; 359 Show; 360 end; 361 end; 362 363 procedure TFormJobProgressView.FormDestroy(Sender:TObject); 364 begin 365 end; 366 367 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem); 368 begin 369 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then 370 with TJob(JobProgressView.Jobs[Item.Index]) do begin 371 Item.Caption := Title; 372 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1 373 else if Finished then Item.ImageIndex := 0 374 else Item.ImageIndex := 2; 375 Item.Data := JobProgressView.Jobs[Item.Index]; 376 end; 377 end; 378 379 procedure TFormJobProgressView.FormClose(Sender: TObject; 380 var CloseAction: TCloseAction); 381 begin 382 ListViewJobs.Clear; 383 end; 384 385 procedure TFormJobProgressView.FormCreate(Sender: TObject); 386 begin 387 Caption := SPleaseWait; 388 try 389 //Animate1.FileName := ExtractFileDir(UTF8Encode(Application.ExeName)) + 390 // DirectorySeparator + 'horse.avi'; 391 //Animate1.Active := True; 392 except 393 394 end; 463 Form.ReloadJobList; 464 end; 465 end; 466 467 procedure TJobProgressView.JobProgressChange(Sender: TObject); 468 begin 469 if Assigned(FOnOwnerDraw) then 470 FOnOwnerDraw(Self); 395 471 end; 396 472 … … 411 487 Sleep(Quantum); 412 488 end; 413 end;414 415 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean);416 begin417 CanClose := JobProgressView.Finished;418 JobProgressView.Terminate := True;419 Caption := SPleaseWait + STerminate;420 489 end; 421 490 … … 475 544 end; 476 545 477 procedure TJobProgressView.ReloadJobList;478 begin479 UpdateHeight;480 // Workaround for not showing first line481 Form.ListViewJobs.Items.Count := Jobs.Count + 1;482 Form.ListViewJobs.Refresh;483 484 if Form.ListViewJobs.Items.Count <> Jobs.Count then485 Form.ListViewJobs.Items.Count := Jobs.Count;486 Form.ListViewJobs.Refresh;487 //Application.ProcessMessages;488 end;489 490 546 constructor TJobProgressView.Create(TheOwner: TComponent); 491 547 begin 492 548 inherited; 493 549 if not (csDesigning in ComponentState) then begin 494 F orm := TFormJobProgressView.Create(Self);495 F orm.JobProgressView := Self;496 end; 497 Jobs := T ObjectList.Create;550 FForm := TFormJobProgressView.Create(Self); 551 FForm.JobProgressView := Self; 552 end; 553 Jobs := TJobs.Create; 498 554 Log := TStringList.Create; 499 555 //PanelOperationsTitle.Height := 80; 500 ShowDelay := 0; //1000; // ms 556 AutoClose := True; 557 ShowDelay := 0; 501 558 end; 502 559 … … 504 561 begin 505 562 Jobs.Clear; 563 Log.Clear; 506 564 //ReloadJobList; 507 565 end; … … 509 567 destructor TJobProgressView.Destroy; 510 568 begin 511 Log.Free; 512 Jobs.Free; 513 inherited Destroy; 514 end; 569 FreeAndNil(Log); 570 FreeAndNil(Jobs); 571 inherited; 572 end; 573 574 { TProgress } 515 575 516 576 procedure TProgress.SetMax(const AValue: Integer); … … 519 579 FLock.Acquire; 520 580 FMax := AValue; 581 if FMax < 1 then FMax := 1; 521 582 if FValue >= FMax then FValue := FMax; 583 finally 584 FLock.Release; 585 end; 586 end; 587 588 procedure TProgress.SetText(AValue: string); 589 begin 590 try 591 FLock.Acquire; 592 if FText = AValue then Exit; 593 FText := AValue; 522 594 finally 523 595 FLock.Release; … … 547 619 end; 548 620 549 { TProgress }550 551 621 procedure TProgress.Increment; 552 622 begin … … 610 680 begin 611 681 Progress.Free; 612 inherited Destroy;682 inherited; 613 683 end; 614 684 -
trunk/Packages/Common/ULastOpenedList.pas
r89 r122 6 6 7 7 uses 8 Classes, SysUtils, Registry, URegistry, Menus ;8 Classes, SysUtils, Registry, URegistry, Menus, XMLConf, DOM; 9 9 10 10 type … … 18 18 procedure SetMaxCount(AValue: Integer); 19 19 procedure LimitMaxCount; 20 procedure ItemsChange(Sender: TObject); 21 procedure DoChange; 20 22 public 21 23 Items: TStringList; … … 25 27 procedure LoadFromRegistry(Context: TRegistryContext); 26 28 procedure SaveToRegistry(Context: TRegistryContext); 29 procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string); 30 procedure SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 27 31 procedure AddItem(FileName: string); 28 32 published … … 38 42 procedure Register; 39 43 begin 40 RegisterComponents(' Samples', [TLastOpenedList]);44 RegisterComponents('Common', [TLastOpenedList]); 41 45 end; 42 46 … … 58 62 end; 59 63 64 procedure TLastOpenedList.ItemsChange(Sender: TObject); 65 begin 66 DoChange; 67 end; 68 69 procedure TLastOpenedList.DoChange; 70 begin 71 if Assigned(FOnChange) then 72 FOnChange(Self); 73 end; 74 60 75 constructor TLastOpenedList.Create(AOwner: TComponent); 61 76 begin 62 77 inherited; 63 78 Items := TStringList.Create; 79 Items.OnChange := ItemsChange; 64 80 MaxCount := 10; 65 81 end; … … 123 139 OpenKey(Context.Key, True); 124 140 for I := 0 to Items.Count - 1 do 125 WriteString('File' + IntToStr(I), UTF8Decode(Items[I]));141 WriteString('File' + IntToStr(I), Items[I]); 126 142 finally 127 143 Free; 144 end; 145 end; 146 147 procedure TLastOpenedList.LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string 148 ); 149 var 150 I: Integer; 151 Value: string; 152 Count: Integer; 153 begin 154 with XMLConfig do begin 155 Count := GetValue(DOMString(Path + '/Count'), 0); 156 if Count > MaxCount then Count := MaxCount; 157 Items.Clear; 158 for I := 0 to Count - 1 do begin 159 Value := string(GetValue(DOMString(Path + '/File' + IntToStr(I)), '')); 160 if Trim(Value) <> '' then Items.Add(Value); 161 end; 162 if Assigned(FOnChange) then 163 FOnChange(Self); 164 end; 165 end; 166 167 procedure TLastOpenedList.SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 168 var 169 I: Integer; 170 begin 171 with XMLConfig do begin 172 SetValue(DOMString(Path + '/Count'), Items.Count); 173 for I := 0 to Items.Count - 1 do 174 SetValue(DOMString(Path + '/File' + IntToStr(I)), DOMString(Items[I])); 175 Flush; 128 176 end; 129 177 end; … … 134 182 Items.Insert(0, FileName); 135 183 LimitMaxCount; 136 if Assigned(FOnChange) then 137 FOnChange(Self); 184 DoChange; 138 185 end; 139 186 -
trunk/Packages/Common/URegistry.pas
r89 r122 9 9 10 10 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)); 11 TRegistryRoot = (rrKeyClassesRoot, rrKeyCurrentUser, rrKeyLocalMachine, 12 rrKeyUsers, rrKeyPerformanceData, rrKeyCurrentConfig, rrKeyDynData); 13 14 { TRegistryContext } 18 15 19 16 TRegistryContext = record 20 17 RootKey: HKEY; 21 18 Key: string; 19 class operator Equal(A, B: TRegistryContext): Boolean; 20 function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; overload; 21 function Create(RootKey: HKEY; Key: string): TRegistryContext; overload; 22 22 end; 23 23 … … 26 26 TRegistryEx = class(TRegistry) 27 27 private 28 function GetCurrentContext: TRegistryContext; 29 procedure SetCurrentContext(AValue: TRegistryContext); 28 30 public 29 31 function ReadBoolWithDefault(const Name: string; … … 35 37 function DeleteKeyRecursive(const Key: string): Boolean; 36 38 function OpenKey(const Key: string; CanCreate: Boolean): Boolean; 39 property CurrentContext: TRegistryContext read GetCurrentContext write SetCurrentContext; 37 40 end; 38 41 39 function RegContext(RootKey: HKEY; Key: string): TRegistryContext; 40 42 const 43 RegistryRootHKEY: array[TRegistryRoot] of HKEY = (HKEY_CLASSES_ROOT, 44 HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, 45 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 41 46 42 47 implementation 43 48 44 function RegContext(RootKey: HKEY; Key: string): TRegistryContext; 49 50 { TRegistryContext } 51 52 class operator TRegistryContext.Equal(A, B: TRegistryContext): Boolean; 53 begin 54 Result := (A.Key = B.Key) and (A.RootKey = B.RootKey); 55 end; 56 57 function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 58 begin 59 Result.RootKey := RegistryRootHKEY[RootKey]; 60 Result.Key := Key; 61 end; 62 63 function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 45 64 begin 46 65 Result.RootKey := RootKey; … … 106 125 end; 107 126 127 function TRegistryEx.GetCurrentContext: TRegistryContext; 128 begin 129 Result.Key := CurrentPath; 130 Result.RootKey := RootKey; 131 end; 132 133 procedure TRegistryEx.SetCurrentContext(AValue: TRegistryContext); 134 begin 135 RootKey := AValue.RootKey; 136 OpenKey(AValue.Key, True); 137 end; 138 108 139 function TRegistryEx.ReadBoolWithDefault(const Name: string; 109 140 DefaultValue: Boolean): Boolean; -
trunk/Packages/Common/UResetableThread.pas
r89 r122 104 104 105 105 procedure TResetableThread.WaitForStart; 106 var107 WaitResult: TWaitResult;106 //var 107 // WaitResult: TWaitResult; 108 108 begin 109 109 //try … … 127 127 128 128 procedure TResetableThread.WaitForStop; 129 var130 WaitState: TWaitResult;129 //var 130 // WaitState: TWaitResult; 131 131 begin 132 132 try … … 156 156 FThread.Name := 'ResetableThread'; 157 157 FThread.Parent := Self; 158 FThread. Resume;158 FThread.Start; 159 159 end; 160 160 -
trunk/Packages/Common/UThreading.pas
r89 r122 30 30 Name: string; 31 31 procedure Execute; virtual; abstract; 32 procedure Resume; virtual; abstract;33 procedure Suspend; virtual; abstract;34 32 procedure Start; virtual; abstract; 35 33 procedure Terminate; virtual; abstract; … … 81 79 procedure Sleep(Delay: Integer); override; 82 80 procedure Execute; override; 83 procedure Resume; override;84 procedure Suspend; override;85 81 procedure Start; override; 86 82 procedure Terminate; override; … … 134 130 Thread.FreeOnTerminate := False; 135 131 Thread.Method := Method; 136 Thread. Resume;132 Thread.Start; 137 133 while (Thread.State = ttsRunning) or (Thread.State = ttsReady) do begin 138 134 if MainThreadID = ThreadID then Application.ProcessMessages; … … 155 151 Thread.Method := Method; 156 152 Thread.OnFinished := CallBack; 157 Thread. Resume;153 Thread.Start; 158 154 //if Thread.State = ttsExceptionOccured then 159 155 // raise Exception.Create(Thread.ExceptionMessage); … … 313 309 procedure TListedThread.Execute; 314 310 begin 315 end;316 317 procedure TListedThread.Resume;318 begin319 FThread.Resume;320 end;321 322 procedure TListedThread.Suspend;323 begin324 FThread.Suspend;325 311 end; 326 312 -
trunk/Packages/Common/UURI.pas
r84 r122 89 89 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 90 90 var 91 I , J: Integer;91 I: Integer; 92 92 Matched: Boolean; 93 93 begin … … 113 113 function RightCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 114 114 var 115 I , J: Integer;115 I: Integer; 116 116 Matched: Boolean; 117 117 begin … … 202 202 203 203 procedure TURI.SetAsString(Value: string); 204 var205 HostAddr: string;206 HostPort: string;207 204 begin 208 205 LeftCutString(Value, Scheme, ':'); … … 326 323 Drive := Drive + DriveSeparator; 327 324 end else Drive := ''; 328 Directory.AsString := AValue; 325 if (Drive <> '') and (AValue = '') then 326 Directory.AsString := Directory.DirSeparator 327 else Directory.AsString := AValue; 329 328 end; 330 329 -
trunk/Packages/Common/UXMLUtils.pas
r89 r122 7 7 uses 8 8 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils ;9 Classes, SysUtils, DateUtils, DOM; 10 10 11 11 function XMLTimeToDateTime(XMLDateTime: string): TDateTime; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 13 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 14 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 15 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 16 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 17 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 18 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 19 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 20 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 21 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 13 23 14 24 … … 20 30 TimeZoneInfo: TTimeZoneInformation; 21 31 begin 32 {$push}{$warn 5057 off} 22 33 case GetTimeZoneInformation(TimeZoneInfo) of 23 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;24 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;34 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 35 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 25 36 else 26 37 Result := 0; 27 38 end; 39 {$pop} 28 40 end; 29 41 {$ELSE} … … 35 47 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 36 48 var 37 I , J: Integer;49 I: Integer; 38 50 Matched: Boolean; 39 51 begin … … 66 78 Minute: Integer; 67 79 Second: Integer; 80 SecondFraction: Double; 68 81 Millisecond: Integer; 69 82 begin … … 88 101 if Pos('Z', XMLDateTime) > 0 then 89 102 LeftCutString(XMLDateTime, Part, 'Z'); 90 Millisecond := StrToInt(Part); 103 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 104 Millisecond := Trunc(SecondFraction * 1000); 91 105 end else begin 92 106 if Pos('+', XMLDateTime) > 0 then … … 106 120 end; 107 121 108 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;122 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 109 123 const 110 124 Neg: array[Boolean] of string = ('+', '-'); … … 123 137 end; 124 138 139 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 140 var 141 NewNode: TDOMNode; 142 begin 143 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 144 NewNode.TextContent := DOMString(IntToStr(Value)); 145 Node.AppendChild(NewNode); 146 end; 147 148 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 149 var 150 NewNode: TDOMNode; 151 begin 152 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 153 NewNode.TextContent := DOMString(IntToStr(Value)); 154 Node.AppendChild(NewNode); 155 end; 156 157 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 158 var 159 NewNode: TDOMNode; 160 begin 161 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 162 NewNode.TextContent := DOMString(BoolToStr(Value)); 163 Node.AppendChild(NewNode); 164 end; 165 166 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 167 var 168 NewNode: TDOMNode; 169 begin 170 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 171 NewNode.TextContent := DOMString(Value); 172 Node.AppendChild(NewNode); 173 end; 174 175 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 176 var 177 NewNode: TDOMNode; 178 begin 179 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 180 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 181 Node.AppendChild(NewNode); 182 end; 183 184 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 185 var 186 NewNode: TDOMNode; 187 begin 188 Result := DefaultValue; 189 NewNode := Node.FindNode(DOMString(Name)); 190 if Assigned(NewNode) then 191 Result := StrToInt(string(NewNode.TextContent)); 192 end; 193 194 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 195 var 196 NewNode: TDOMNode; 197 begin 198 Result := DefaultValue; 199 NewNode := Node.FindNode(DOMString(Name)); 200 if Assigned(NewNode) then 201 Result := StrToInt64(string(NewNode.TextContent)); 202 end; 203 204 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 205 var 206 NewNode: TDOMNode; 207 begin 208 Result := DefaultValue; 209 NewNode := Node.FindNode(DOMString(Name)); 210 if Assigned(NewNode) then 211 Result := StrToBool(string(NewNode.TextContent)); 212 end; 213 214 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 215 var 216 NewNode: TDOMNode; 217 begin 218 Result := DefaultValue; 219 NewNode := Node.FindNode(DOMString(Name)); 220 if Assigned(NewNode) then 221 Result := string(NewNode.TextContent); 222 end; 223 224 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime 225 ): TDateTime; 226 var 227 NewNode: TDOMNode; 228 begin 229 Result := DefaultValue; 230 NewNode := Node.FindNode(DOMString(Name)); 231 if Assigned(NewNode) then 232 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 233 end; 234 125 235 end. 126 236 -
trunk/Packages/CoolWeb/WebServer/UHTTPServer.pas
r100 r122 232 232 end else 233 233 with Response.Content do begin 234 WriteLn(Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)]));234 //WriteLn(Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)])); 235 235 WriteString('<html><body>' + Format(SFileNotFound, [Request.Path.Implode('/', StrToStr)]) + '</body></html>'); 236 236 end;
Note:
See TracChangeset
for help on using the changeset viewer.