Changeset 102 for trunk/Packages


Ignore:
Timestamp:
Dec 9, 2024, 11:55:53 AM (3 weeks ago)
Author:
chronos
Message:
  • Modified: Lowered minimal swipe distance.
  • Modified: Show score and best score as boxes. Place them according window size.
  • Modified: Updated Common package.
Location:
trunk/Packages/Common
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Common.lpk

    r85 r102  
    4343    <License Value="Copy left."/>
    4444    <Version Minor="12"/>
    45     <Files Count="36">
     45    <Files Count="37">
    4646      <Item1>
    4747        <Filename Value="StopWatch.pas"/>
     
    201201        <UnitName Value="FormAbout"/>
    202202      </Item36>
     203      <Item37>
     204        <Filename Value="Forms\FormKeyShortcuts.pas"/>
     205        <UnitName Value="FormKeyShortcuts"/>
     206      </Item37>
    203207    </Files>
    204208    <CompatibilityMode Value="True"/>
  • trunk/Packages/Common/Common.pas

    r99 r102  
    5555function EndsWith(Text, What: string): Boolean;
    5656function Explode(Separator: Char; Data: string): TStringArray;
    57 procedure ExecuteProgram(Executable: string; Parameters: array of string);
     57procedure ExecuteProgram(Executable: string; Parameters: array of string;
     58  Environment: array of string; CurrentDirectory: string = '');
     59procedure ExecuteProgramOutput(Executable: string; Parameters: array of string;
     60  Environment: array of string; out Output, Error: string;
     61  out ExitCode: Integer; CurrentDirectory: string = '');
    5862procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
    5963procedure FreeThenNil(var Obj);
     
    6367function GetBit(Variable: QWord; Index: Byte): Boolean;
    6468function GetStringPart(var Text: string; Separator: string): string;
     69function GetEnvironmentVariables: TStringArray;
    6570function GenerateNewName(OldName: string): string;
    6671function GetFileFilterItemExt(Filter: string; Index: Integer): string;
    6772function 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;
     73function Implode(Separator: string; List: TList<string>): string; overload;
     74function Implode(Separator: string; List: array of string): string; overload;
     75function Implode(Separator: string; List: TStringList; Around: string = ''): string; overload;
    7076function LastPos(const SubStr: String; const S: String): Integer;
    7177function LoadFileToStr(const FileName: TFileName): AnsiString;
     
    98104implementation
    99105
     106resourcestring
     107  SExecutionError = 'Excution error: %s (exit code: %d)';
     108
    100109function StartsWith(Text, What: string): Boolean;
    101110begin
     
    108117end;
    109118
    110 function BinToInt(BinStr : string) : Int64;
    111 var
    112   i : byte;
    113   RetVar : Int64;
     119function BinToInt(BinStr: string): Int64;
     120var
     121  I: Byte;
     122  RetVar: Int64;
    114123begin
    115124  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);
    117126  RetVar := 0;
    118   for i := 1 to length(BinStr) do begin
    119     if not (BinStr[i] in ['0','1']) then begin
     127  for I := 1 to Length(BinStr) do begin
     128    if not (BinStr[I] in ['0','1']) then begin
    120129      RetVar := 0;
    121130      Break;
    122131    end;
    123     RetVar := (RetVar shl 1) + (byte(BinStr[i]) and 1) ;
     132    RetVar := (RetVar shl 1) + (Byte(BinStr[I]) and 1);
    124133  end;
    125134
     
    136145  end;
    137146end;
    138 
    139147
    140148procedure DeleteFiles(APath, AFileSpec: string);
     
    154162  FindClose(SearchRec);
    155163end;
    156 
    157164
    158165function GetFileFilterItemExt(Filter: string; Index: Integer): string;
     
    177184  if FileExt <> '.*' then
    178185    FileDialog.FileName := ChangeFileExt(FileDialog.FileName, FileExt)
     186end;
     187
     188function GetEnvironmentVariables: TStringArray;
     189var
     190  I: Integer;
     191begin
     192  SetLength(Result, GetEnvironmentVariableCount);
     193  for I := 0 to GetEnvironmentVariableCount - 1 do
     194    Result[I] := GetEnvironmentString(I);
    179195end;
    180196
     
    219235end;*)
    220236
     237function Implode(Separator: string; List: array of string): string;
     238var
     239  I: Integer;
     240begin
     241  Result := '';
     242  for I := 0 to Length(List) - 1 do begin
     243    Result := Result + List[I];
     244    if I < Length(List) - 1 then Result := Result + Separator;
     245  end;
     246end;
     247
    221248function Implode(Separator: string; List: TStringList; Around: string = ''): string;
    222249var
     
    494521end;
    495522
    496 procedure ExecuteProgram(Executable: string; Parameters: array of string);
     523procedure ExecuteProgram(Executable: string; Parameters: array of string;
     524  Environment: array of string; CurrentDirectory: string = '');
    497525var
    498526  Process: TProcess;
    499527  I: Integer;
    500528begin
     529  Process := TProcess.Create(nil);
    501530  try
    502     Process := TProcess.Create(nil);
    503531    Process.Executable := Executable;
    504532    for I := 0 to Length(Parameters) - 1 do
    505533      Process.Parameters.Add(Parameters[I]);
     534    for I := 0 to Length(Environment) - 1 do
     535      Process.Environment.Add(Environment[I]);
     536    Process.CurrentDirectory := CurrentDirectory;
     537    Process.ShowWindow := swoHIDE;
    506538    Process.Options := [poNoConsole];
    507539    Process.Execute;
     
    511543end;
    512544
     545procedure ExecuteProgramOutput(Executable: string; Parameters: array of string;
     546  Environment: array of string; out Output, Error: string; out ExitCode: Integer;
     547  CurrentDirectory: string);
     548var
     549  Process: TProcess;
     550  I: Integer;
     551  ReadCount: Integer;
     552  Buffer: string;
     553const
     554  BufferSize = 1000;
     555begin
     556  Process := TProcess.Create(nil);
     557  try
     558    Process.Executable := Executable;
     559    for I := 0 to Length(Parameters) - 1 do
     560      Process.Parameters.Add(Parameters[I]);
     561    for I := 0 to Length(Environment) - 1 do
     562      Process.Environment.Add(Environment[I]);
     563    Process.CurrentDirectory := CurrentDirectory;
     564    Process.ShowWindow := swoHIDE;
     565    Process.Options := [poNoConsole, poUsePipes];
     566    Process.Execute;
     567
     568    Output := '';
     569    Error := '';
     570    Buffer := '';
     571    SetLength(Buffer, BufferSize);
     572    while Process.Running do begin
     573      if Process.Output.NumBytesAvailable > 0 then begin
     574        ReadCount := Process.Output.Read(Buffer[1], Length(Buffer));
     575        Output := Output + Copy(Buffer, 1, ReadCount);
     576      end;
     577
     578      if Process.Stderr.NumBytesAvailable > 0 then begin
     579        ReadCount := Process.Stderr.Read(Buffer[1], Length(Buffer));
     580        Error := Error + Copy(Buffer, 1, ReadCount)
     581      end;
     582
     583      Sleep(10);
     584    end;
     585
     586    if Process.Output.NumBytesAvailable > 0 then begin
     587      ReadCount := Process.Output.Read(Buffer[1], Length(Buffer));
     588      Output := Output + Copy(Buffer, 1, ReadCount);
     589    end;
     590
     591    if Process.Stderr.NumBytesAvailable > 0 then begin
     592      ReadCount := Process.Stderr.Read(Buffer[1], Length(Buffer));
     593      Error := Error + Copy(Buffer, 1, ReadCount);
     594    end;
     595
     596    ExitCode := Process.ExitCode;
     597
     598    if (ExitCode <> 0) or (Error <> '') then
     599      raise Exception.Create(Format(SExecutionError, [Output + Error, ExitCode]));
     600  finally
     601    Process.Free;
     602  end;
     603end;
     604
    513605procedure FreeThenNil(var Obj);
    514606begin
     
    529621procedure OpenFileInShell(FileName: string);
    530622begin
    531   ExecuteProgram('cmd.exe', ['/c', 'start', FileName]);
     623  ExecuteProgram('cmd.exe', ['/c', 'start', FileName], []);
    532624end;
    533625
  • trunk/Packages/Common/CommonPackage.pas

    r85 r102  
    1414  ScaleDPI, Theme, StringTable, MetaCanvas, Geometric, Translator, Languages,
    1515  PixelPointer, DataFile, TestCase, Generics, Table, FormEx, FormTests,
    16   FormTest, FormAbout, LazarusPackageIntf;
     16  FormTest, FormAbout, FormKeyShortcuts, LazarusPackageIntf;
    1717
    1818implementation
  • trunk/Packages/Common/FormEx.pas

    r99 r102  
    8282procedure TFormEx.DoClose(var CloseAction: TCloseAction);
    8383begin
    84   if  (not (csDesigning in ComponentState)) then begin
     84  if (not (csDesigning in ComponentState)) then begin
    8585    PersistentForm.FormFullScreen := FullScreen;
    8686    PersistentForm.Save(Self);
  • trunk/Packages/Common/Forms/FormAbout.lfm

    r90 r102  
    11object FormAbout: TFormAbout
    2   Left = 929
     2  Left = 624
    33  Height = 402
    4   Top = 519
     4  Top = 622
    55  Width = 702
    66  Caption = 'About'
     
    1010  OnShow = FormShow
    1111  Position = poScreenCenter
    12   LCLVersion = '3.4.0.0'
     12  LCLVersion = '2.2.6.0'
    1313  object LabelDescription: TLabel
    1414    Left = 30
     
    8888      Anchors = [akLeft, akBottom]
    8989      Caption = 'Home page'
     90      OnClick = ButtonHomePageClick
    9091      ParentFont = False
    9192      TabOrder = 0
    92       OnClick = ButtonHomePageClick
    9393    end
    9494    object ButtonClose: TButton
  • trunk/Packages/Common/ListViewSort.pas

    r89 r102  
    358358    List.Clear;
    359359    List.AddRange(Source);
    360   end else List.Clear;
     360  end;
    361361  if ListView.Items.Count <> List.Count then
    362362    ListView.Items.Count := List.Count;
  • trunk/Packages/Common/PersistentForm.pas

    r99 r102  
    336336    end;
    337337    Form.OnWindowStateChange := OldHandler;
     338    FormFullScreen := True;
    338339    {$ENDIF}
    339340  end else begin
  • trunk/Packages/Common/Table.pas

    r85 r102  
    44
    55uses
    6   Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, XMLWrite, DOM;
     6  Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, DOM;
    77
    88type
Note: See TracChangeset for help on using the changeset viewer.