Changeset 74 for trunk/Packages/Common
- Timestamp:
- Jan 18, 2018, 11:54:13 PM (7 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Common.lpk
r73 r74 1 <?xml version="1.0" ?>1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <CONFIG> 3 3 <Package Version="4"> … … 22 22 <License Value="GNU/GPL"/> 23 23 <Version Minor="7"/> 24 <Files Count="1 7">24 <Files Count="19"> 25 25 <Item1> 26 26 <Filename Value="StopWatch.pas"/> … … 93 93 <Item17> 94 94 <Filename Value="UListViewSort.pas"/> 95 <HasRegisterProc Value="True"/> 95 96 <UnitName Value="UListViewSort"/> 96 97 </Item17> 98 <Item18> 99 <Filename Value="UPersistentForm.pas"/> 100 <HasRegisterProc Value="True"/> 101 <UnitName Value="UPersistentForm"/> 102 </Item18> 103 <Item19> 104 <Filename Value="UFindFile.pas"/> 105 <HasRegisterProc Value="True"/> 106 <UnitName Value="UFindFile"/> 107 </Item19> 97 108 </Files> 98 109 <i18n> -
trunk/Packages/Common/Common.pas
r73 r74 11 11 UMemory, UResetableThread, UPool, ULastOpenedList, URegistry, 12 12 UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort, 13 LazarusPackageIntf;13 UPersistentForm, UFindFile, LazarusPackageIntf; 14 14 15 15 implementation … … 21 21 RegisterUnit('UJobProgressView', @UJobProgressView.Register); 22 22 RegisterUnit('UApplicationInfo', @UApplicationInfo.Register); 23 RegisterUnit('UListViewSort', @UListViewSort.Register); 24 RegisterUnit('UPersistentForm', @UPersistentForm.Register); 25 RegisterUnit('UFindFile', @UFindFile.Register); 23 26 end; 24 27 -
trunk/Packages/Common/UApplicationInfo.pas
r73 r74 55 55 procedure Register; 56 56 begin 57 RegisterComponents(' Samples', [TApplicationInfo]);57 RegisterComponents('Common', [TApplicationInfo]); 58 58 end; 59 59 -
trunk/Packages/Common/UCommon.pas
r73 r74 6 6 7 7 uses 8 {$IFDEF Windows}Windows,{$ENDIF} 8 {$ifdef Windows}Windows,{$endif} 9 {$ifdef Linux}baseunix,{$endif} 9 10 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 10 11 FileUtil; //, ShFolder, ShellAPI; … … 64 65 procedure ExecuteProgram(CommandLine: string); 65 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; 66 73 67 74 … … 107 114 Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec); 108 115 while Find = 0 do begin 109 DeleteFile UTF8(Path + UTF8Encode(SearchRec.Name));116 DeleteFile(Path + UTF8Encode(SearchRec.Name)); 110 117 111 118 Find := SysUtils.FindNext(SearchRec); … … 286 293 L: LongWord; 287 294 begin 288 289 295 L := MAX_USERNAME_LENGTH + 2; 290 296 SetLength(Result, L); … … 301 307 end; 302 308 end; 303 309 {$endif} 310 311 function ComputerName: string; 312 {$ifdef mswindows} 313 const 314 INFO_BUFFER_SIZE = 32767; 315 var 316 Buffer : array[0..INFO_BUFFER_SIZE] of WideChar; 317 Ret : DWORD; 318 begin 319 Ret := INFO_BUFFER_SIZE; 320 If (GetComputerNameW(@Buffer[0],Ret)) then begin 321 Result := UTF8Encode(WideString(Buffer)); 322 end 323 else begin 324 Result := 'ERROR_NO_COMPUTERNAME_RETURNED'; 325 end; 326 end; 327 {$endif} 328 {$ifdef unix} 329 var 330 Name: UtsName; 331 begin 332 fpuname(Name); 333 Result := Name.Nodename; 334 end; 335 {$endif} 336 337 {$ifdef windows} 304 338 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 305 339 const … … 416 450 417 451 procedure OpenWebPage(URL: string); 418 var419 Process: TProcess;420 Browser, Params: string;421 452 begin 422 453 OpenURL(URL); 423 {try 424 Process := TProcess.Create(nil); 425 Browser := ''; 426 //FindDefaultBrowser(Browser, Params); 427 //Process.Executable := Browser; 428 //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]); 429 Process.CommandLine := 'cmd.exe /c start ' + URL; 430 Process.Options := [poNoConsole]; 431 Process.Execute; 454 end; 455 456 procedure OpenFileInShell(FileName: string); 457 begin 458 ExecuteProgram('cmd.exe /c start "' + FileName + '"'); 459 end; 460 461 function RemoveQuotes(Text: string): string; 462 begin 463 Result := Text; 464 if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then 465 Result := Copy(Text, 2, Length(Text) - 2); 466 end; 467 468 function OccurenceOfChar(What: Char; Where: string): Integer; 469 var 470 I: Integer; 471 begin 472 Result := 0; 473 for I := 1 to Length(Where) do 474 if Where[I] = What then Inc(Result); 475 end; 476 477 function GetDirCount(Dir: string): Integer; 478 begin 479 Result := OccurenceOfChar(DirectorySeparator, Dir); 480 if Copy(Dir, Length(Dir), 1) = DirectorySeparator then 481 Dec(Result); 482 end; 483 484 function MergeArray(A, B: array of string): TArrayOfString; 485 var 486 I: Integer; 487 begin 488 SetLength(Result, Length(A) + Length(B)); 489 for I := 0 to Length(A) - 1 do 490 Result[I] := A[I]; 491 for I := 0 to Length(B) - 1 do 492 Result[Length(A) + I] := B[I]; 493 end; 494 495 function LoadFileToStr(const FileName: TFileName): AnsiString; 496 var 497 FileStream: TFileStream; 498 Read: Integer; 499 begin 500 Result := ''; 501 FileStream := TFileStream.Create(FileName, fmOpenRead); 502 try 503 if FileStream.Size > 0 then begin 504 SetLength(Result, FileStream.Size); 505 Read := FileStream.Read(Pointer(Result)^, FileStream.Size); 506 SetLength(Result, Read); 507 end; 432 508 finally 433 Process.Free; 434 end;} 435 end; 436 437 procedure OpenFileInShell(FileName: string); 438 begin 439 ExecuteProgram('cmd.exe /c start "' + FileName + '"'); 440 end; 509 FileStream.Free; 510 end; 511 end; 512 513 441 514 442 515 initialization -
trunk/Packages/Common/UDebugLog.pas
r73 r74 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)105 ForceDirectories(ExtractFileDir(FileName)); 106 if FileExists(FileName) then LogFile := TFileStream.Create(UTF8Decode(FileName), fmOpenWrite) 107 107 else LogFile := TFileStream.Create(UTF8Decode(FileName), fmCreate); 108 108 LogFile.Seek(0, soFromEnd); -
trunk/Packages/Common/UFindFile.pas
r73 r74 64 64 procedure Register; 65 65 begin 66 RegisterComponents(' Samples', [TFindFile]);66 RegisterComponents('Common', [TFindFile]); 67 67 end; 68 68 -
trunk/Packages/Common/UJobProgressView.pas
r73 r74 169 169 procedure Register; 170 170 begin 171 RegisterComponents(' Samples', [TJobProgressView]);171 RegisterComponents('Common', [TJobProgressView]); 172 172 end; 173 173 -
trunk/Packages/Common/ULastOpenedList.pas
r73 r74 40 40 procedure Register; 41 41 begin 42 RegisterComponents(' Samples', [TLastOpenedList]);42 RegisterComponents('Common', [TLastOpenedList]); 43 43 end; 44 44 -
trunk/Packages/Common/UListViewSort.pas
r73 r74 9 9 uses 10 10 {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils, 11 Controls, DateUtils, Dialogs, SpecializedList ;11 Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls; 12 12 13 13 type … … 19 19 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 20 20 21 TListViewSort = class 21 TListViewSort = class(TComponent) 22 22 private 23 23 FListView: TListView; … … 43 43 List: TListObject; 44 44 Source: TListObject; 45 constructor Create ;45 constructor Create(AOwner: TComponent); override; 46 46 destructor Destroy; override; 47 47 function CompareTime(Time1, Time2: TDateTime): Integer; … … 50 50 function CompareBoolean(Value1, Value2: Boolean): Integer; 51 51 procedure Refresh; 52 published 52 53 property ListView: TListView read FListView write SetListView; 53 54 property OnCompareItem: TCompareEvent read FOnCompareItem … … 61 62 end; 62 63 64 { TListViewFilter } 65 66 TListViewFilter = class(TWinControl) 67 private 68 FOnChange: TNotifyEvent; 69 FStringGrid1: TStringGrid; 70 procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 71 public 72 constructor Create(AOwner: TComponent); override; 73 procedure UpdateFromListView(ListView: TListView); 74 function TextEntered: Boolean; 75 function GetColValue(Index: Integer): string; 76 property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1; 77 published 78 property OnChange: TNotifyEvent read FOnChange write FOnChange; 79 property Align; 80 property Anchors; 81 end; 82 83 procedure Register; 84 85 63 86 implementation 87 88 procedure Register; 89 begin 90 RegisterComponents('Common', [TListViewSort, TListViewFilter]); 91 end; 92 93 { TListViewFilter } 94 95 procedure TListViewFilter.DoOnKeyUp(Sender: TObject; var Key: Word; 96 Shift: TShiftState); 97 begin 98 if Assigned(FOnChange) then 99 FOnChange(Self); 100 end; 101 102 constructor TListViewFilter.Create(AOwner: TComponent); 103 begin 104 inherited Create(AOwner); 105 FStringGrid1 := TStringGrid.Create(Self); 106 FStringGrid1.Align := alClient; 107 FStringGrid1.Parent := Self; 108 FStringGrid1.Visible := True; 109 FStringGrid1.ScrollBars := ssNone; 110 FStringGrid1.FixedCols := 0; 111 FStringGrid1.FixedRows := 0; 112 FStringGrid1.RowCount := 1; 113 FStringGrid1.Options := [goFixedHorzLine, goFixedVertLine, goVertLine, 114 goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]; 115 FStringGrid1.OnKeyUp := DoOnKeyUp; 116 end; 117 118 procedure TListViewFilter.UpdateFromListView(ListView: TListView); 119 var 120 I: Integer; 121 NewColumn: TGridColumn; 122 begin 123 with FStringGrid1 do begin 124 Columns.Clear; 125 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 126 while Columns.Count < ListView.Columns.Count do NewColumn := Columns.Add; 127 for I := 0 to ListView.Columns.Count - 1 do begin 128 Columns[I].Width := ListView.Columns[I].Width; 129 end; 130 end; 131 end; 132 133 function TListViewFilter.TextEntered: Boolean; 134 var 135 I: Integer; 136 begin 137 Result := False; 138 for I := 0 to FStringGrid1.ColCount - 1 do begin 139 if FStringGrid1.Cells[I, 0] <> '' then begin 140 Result := True; 141 Break; 142 end; 143 end; 144 end; 145 146 function TListViewFilter.GetColValue(Index: Integer): string; 147 begin 148 if (Index >= 0) and (Index < StringGrid.Columns.Count) then 149 Result := StringGrid.Cells[Index, 0] 150 else Result := ''; 151 end; 64 152 65 153 { TListViewSort } … … 160 248 end; 161 249 162 constructor TListViewSort.Create; 163 begin 250 constructor TListViewSort.Create(AOwner: TComponent); 251 begin 252 inherited; 164 253 List := TListObject.Create; 165 254 List.OwnsObjects := False; -
trunk/Packages/Common/URegistry.pas
r73 r74 17 17 rrKeyDynData = HKEY($80000006)); 18 18 19 { TRegistryContext } 20 19 21 TRegistryContext = record 20 22 RootKey: HKEY; 21 23 Key: string; 24 class operator Equal(A, B: TRegistryContext): Boolean; 22 25 end; 23 26 … … 49 52 Result.RootKey := RootKey; 50 53 Result.Key := Key; 54 end; 55 56 { TRegistryContext } 57 58 class operator TRegistryContext.Equal(A, B: TRegistryContext): Boolean; 59 begin 60 Result := (A.Key = B.Key) and (A.RootKey = B.RootKey); 51 61 end; 52 62
Note:
See TracChangeset
for help on using the changeset viewer.