Changeset 332 for trunk/Packages/Common
- Timestamp:
- Aug 27, 2024, 3:48:44 PM (4 months ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 7 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Common.lpk
r315 r332 43 43 <License Value="Copy left."/> 44 44 <Version Minor="12"/> 45 <Files Count="3 6">45 <Files Count="37"> 46 46 <Item1> 47 47 <Filename Value="StopWatch.pas"/> … … 201 201 <UnitName Value="FormAbout"/> 202 202 </Item36> 203 <Item37> 204 <Filename Value="Forms\FormKeyShortcuts.pas"/> 205 <UnitName Value="FormKeyShortcuts"/> 206 </Item37> 203 207 </Files> 204 208 <CompatibilityMode Value="True"/> -
trunk/Packages/Common/Common.pas
r328 r332 55 55 function EndsWith(Text, What: string): Boolean; 56 56 function Explode(Separator: Char; Data: string): TStringArray; 57 procedure ExecuteProgram(Executable: string; Parameters: array of string); 57 procedure ExecuteProgram(Executable: string; Parameters: array of string; 58 Environment: array of string; CurrentDirectory: string = ''); 59 procedure ExecuteProgramOutput(Executable: string; Parameters: array of string; 60 Environment: array of string; out Output, Error: string; 61 out ExitCode: Integer; CurrentDirectory: string = ''); 58 62 procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog); 59 63 procedure FreeThenNil(var Obj); … … 63 67 function GetBit(Variable: QWord; Index: Byte): Boolean; 64 68 function GetStringPart(var Text: string; Separator: string): string; 69 function GetEnvironmentVariables: TStringArray; 65 70 function GenerateNewName(OldName: string): string; 66 71 function GetFileFilterItemExt(Filter: string; Index: Integer): string; 67 72 function IntToBin(Data: Int64; Count: Byte): string; 68 function Implode(Separator: string; List: TList<string>): string; 69 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 73 function Implode(Separator: string; List: TList<string>): string; overload; 74 function Implode(Separator: string; List: array of string): string; overload; 75 function Implode(Separator: string; List: TStringList; Around: string = ''): string; overload; 70 76 function LastPos(const SubStr: String; const S: String): Integer; 71 77 function LoadFileToStr(const FileName: TFileName): AnsiString; … … 98 104 implementation 99 105 106 resourcestring 107 SExecutionError = 'Excution error: %s (exit code: %d)'; 108 100 109 function StartsWith(Text, What: string): Boolean; 101 110 begin … … 108 117 end; 109 118 110 function BinToInt(BinStr : string): Int64;111 var 112 i : byte;113 RetVar 119 function BinToInt(BinStr: string): Int64; 120 var 121 I: Byte; 122 RetVar: Int64; 114 123 begin 115 124 BinStr := UpperCase(BinStr); 116 if BinStr[length(BinStr)] = 'B' then Delete(BinStr, length(BinStr),1);125 if BinStr[length(BinStr)] = 'B' then Delete(BinStr, Length(BinStr), 1); 117 126 RetVar := 0; 118 for i := 1 to length(BinStr) do begin119 if not (BinStr[ i] in ['0','1']) then begin127 for I := 1 to Length(BinStr) do begin 128 if not (BinStr[I] in ['0','1']) then begin 120 129 RetVar := 0; 121 130 Break; 122 131 end; 123 RetVar := (RetVar shl 1) + ( byte(BinStr[i]) and 1);132 RetVar := (RetVar shl 1) + (Byte(BinStr[I]) and 1); 124 133 end; 125 134 … … 136 145 end; 137 146 end; 138 139 147 140 148 procedure DeleteFiles(APath, AFileSpec: string); … … 154 162 FindClose(SearchRec); 155 163 end; 156 157 164 158 165 function GetFileFilterItemExt(Filter: string; Index: Integer): string; … … 177 184 if FileExt <> '.*' then 178 185 FileDialog.FileName := ChangeFileExt(FileDialog.FileName, FileExt) 186 end; 187 188 function GetEnvironmentVariables: TStringArray; 189 var 190 I: Integer; 191 begin 192 Result := Default(TStringArray); 193 SetLength(Result, GetEnvironmentVariableCount); 194 for I := 0 to GetEnvironmentVariableCount - 1 do 195 Result[I] := GetEnvironmentString(I); 179 196 end; 180 197 … … 219 236 end;*) 220 237 238 function Implode(Separator: string; List: array of string): string; 239 var 240 I: Integer; 241 begin 242 Result := ''; 243 for I := 0 to Length(List) - 1 do begin 244 Result := Result + List[I]; 245 if I < Length(List) - 1 then Result := Result + Separator; 246 end; 247 end; 248 221 249 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 222 250 var … … 494 522 end; 495 523 496 procedure ExecuteProgram(Executable: string; Parameters: array of string); 524 procedure ExecuteProgram(Executable: string; Parameters: array of string; 525 Environment: array of string; CurrentDirectory: string = ''); 497 526 var 498 527 Process: TProcess; 499 528 I: Integer; 500 529 begin 530 Process := TProcess.Create(nil); 501 531 try 502 Process := TProcess.Create(nil);503 532 Process.Executable := Executable; 504 533 for I := 0 to Length(Parameters) - 1 do 505 534 Process.Parameters.Add(Parameters[I]); 535 for I := 0 to Length(Environment) - 1 do 536 Process.Environment.Add(Environment[I]); 537 Process.CurrentDirectory := CurrentDirectory; 538 Process.ShowWindow := swoHIDE; 506 539 Process.Options := [poNoConsole]; 507 540 Process.Execute; … … 511 544 end; 512 545 546 procedure ExecuteProgramOutput(Executable: string; Parameters: array of string; 547 Environment: array of string; out Output, Error: string; out ExitCode: Integer; 548 CurrentDirectory: string); 549 var 550 Process: TProcess; 551 I: Integer; 552 ReadCount: Integer; 553 Buffer: string; 554 const 555 BufferSize = 1000; 556 begin 557 Process := TProcess.Create(nil); 558 try 559 Process.Executable := Executable; 560 for I := 0 to Length(Parameters) - 1 do 561 Process.Parameters.Add(Parameters[I]); 562 for I := 0 to Length(Environment) - 1 do 563 Process.Environment.Add(Environment[I]); 564 Process.CurrentDirectory := CurrentDirectory; 565 Process.ShowWindow := swoHIDE; 566 Process.Options := [poNoConsole, poUsePipes]; 567 Process.Execute; 568 569 Output := ''; 570 Error := ''; 571 Buffer := ''; 572 SetLength(Buffer, BufferSize); 573 while Process.Running do begin 574 if Process.Output.NumBytesAvailable > 0 then begin 575 ReadCount := Process.Output.Read(Buffer[1], Length(Buffer)); 576 Output := Output + Copy(Buffer, 1, ReadCount); 577 end; 578 579 if Process.Stderr.NumBytesAvailable > 0 then begin 580 ReadCount := Process.Stderr.Read(Buffer[1], Length(Buffer)); 581 Error := Error + Copy(Buffer, 1, ReadCount) 582 end; 583 584 Sleep(10); 585 end; 586 587 if Process.Output.NumBytesAvailable > 0 then begin 588 ReadCount := Process.Output.Read(Buffer[1], Length(Buffer)); 589 Output := Output + Copy(Buffer, 1, ReadCount); 590 end; 591 592 if Process.Stderr.NumBytesAvailable > 0 then begin 593 ReadCount := Process.Stderr.Read(Buffer[1], Length(Buffer)); 594 Error := Error + Copy(Buffer, 1, ReadCount); 595 end; 596 597 ExitCode := Process.ExitCode; 598 599 if (ExitCode <> 0) or (Error <> '') then 600 raise Exception.Create(Format(SExecutionError, [Output + Error, ExitCode])); 601 finally 602 Process.Free; 603 end; 604 end; 605 513 606 procedure FreeThenNil(var Obj); 514 607 begin … … 529 622 procedure OpenFileInShell(FileName: string); 530 623 begin 531 ExecuteProgram('cmd.exe', ['/c', 'start', FileName] );624 ExecuteProgram('cmd.exe', ['/c', 'start', FileName], []); 532 625 end; 533 626 -
trunk/Packages/Common/CommonPackage.pas
r315 r332 14 14 ScaleDPI, Theme, StringTable, MetaCanvas, Geometric, Translator, Languages, 15 15 PixelPointer, DataFile, TestCase, Generics, Table, FormEx, FormTests, 16 FormTest, FormAbout, LazarusPackageIntf;16 FormTest, FormAbout, FormKeyShortcuts, LazarusPackageIntf; 17 17 18 18 implementation -
trunk/Packages/Common/FormEx.pas
r328 r332 82 82 procedure TFormEx.DoClose(var CloseAction: TCloseAction); 83 83 begin 84 if 84 if (not (csDesigning in ComponentState)) then begin 85 85 PersistentForm.FormFullScreen := FullScreen; 86 86 PersistentForm.Save(Self); -
trunk/Packages/Common/ListViewSort.pas
r315 r332 358 358 List.Clear; 359 359 List.AddRange(Source); 360 end else List.Clear;360 end; 361 361 if ListView.Items.Count <> List.Count then 362 362 ListView.Items.Count := List.Count; -
trunk/Packages/Common/PersistentForm.pas
r328 r332 336 336 end; 337 337 Form.OnWindowStateChange := OldHandler; 338 FormFullScreen := True; 338 339 {$ENDIF} 339 340 end else begin -
trunk/Packages/Common/Table.pas
r315 r332 4 4 5 5 uses 6 Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, XMLWrite,DOM;6 Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, DOM; 7 7 8 8 type
Note:
See TracChangeset
for help on using the changeset viewer.