Ignore:
Timestamp:
Jun 21, 2022, 5:04:48 PM (23 months ago)
Author:
chronos
Message:
  • Fixed: Calculation of tracks end.
  • Modified: Updated Common package to version 0.10.
  • Modified: Build with Lazarus 2.2.2.
  • Modified: Used Generics.Collections instead of fgl for generic lists.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UCommon.pas

    r83 r86  
    11unit UCommon;
    22
    3 {$mode delphi}
    4 
    53interface
    64
    75uses
    8   {$ifdef Windows}Windows,{$endif}
    9   {$ifdef Linux}baseunix,{$endif}
    10   Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
     6  {$IFDEF WINDOWS}Windows,{$ENDIF}
     7  {$IFDEF UNIX}baseunix,{$ENDIF}
     8  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, Graphics,
    119  FileUtil; //, ShFolder, ShellAPI;
    1210
    1311type
    1412  TArrayOfByte = array of Byte;
    15   TArrayOfString = array of string;
    1613  TExceptionEvent = procedure(Sender: TObject; E: Exception) of object;
    1714
     
    3532  DLLHandle1: HModule;
    3633
    37 {$IFDEF Windows}
    38   GetUserNameEx: procedure (NameFormat: DWORD;
    39     lpNameBuffer: LPSTR; nSize: PULONG); stdcall;
    40 {$ENDIF}
     34  {$IFDEF WINDOWS}
     35    GetUserNameEx: procedure (NameFormat: DWORD;
     36      lpNameBuffer: LPSTR; nSize: PULONG); stdcall;
     37  {$ENDIF}
     38
     39const
     40  clLightBlue = TColor($FF8080);
     41  clLightGreen = TColor($80FF80);
     42  clLightRed = TColor($8080FF);
    4143
    4244function AddLeadingZeroes(const aNumber, Length : integer) : string;
     
    5153function ComputerName: string;
    5254procedure DeleteFiles(APath, AFileSpec: string);
     55function Explode(Separator: Char; Data: string): TStringArray;
    5356procedure ExecuteProgram(Executable: string; Parameters: array of string);
    5457procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
     
    6568function LoadFileToStr(const FileName: TFileName): AnsiString;
    6669function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    67 function MergeArray(A, B: array of string): TArrayOfString;
     70function MergeArray(A, B: array of string): TStringArray;
    6871function OccurenceOfChar(What: Char; Where: string): Integer;
    6972procedure OpenWebPage(URL: string);
     73procedure OpenEmail(Email: string);
    7074procedure OpenFileInShell(FileName: string);
    7175function PosFromIndex(SubStr: string; Text: string;
     
    8387function SplitString(var Text: string; Count: Word): string;
    8488function StripTags(const S: string): string;
    85 function TryHexToInt(Data: string; var Value: Integer): Boolean;
    86 function TryBinToInt(Data: string; var Value: Integer): Boolean;
     89function TryHexToInt(Data: string; out Value: Integer): Boolean;
     90function TryBinToInt(Data: string; out Value: Integer): Boolean;
    8791procedure SortStrings(Strings: TStrings);
    8892
     
    246250end;
    247251
    248 function TryHexToInt(Data: string; var Value: Integer): Boolean;
     252function TryHexToInt(Data: string; out Value: Integer): Boolean;
    249253var
    250254  I: Integer;
     
    262266end;
    263267
    264 function TryBinToInt(Data: string; var Value: Integer): Boolean;
     268function TryBinToInt(Data: string; out Value: Integer): Boolean;
    265269var
    266270  I: Integer;
     
    290294end;
    291295
    292 function Explode(Separator: char; Data: string): TArrayOfString;
    293 begin
    294   SetLength(Result, 0);
    295   while Pos(Separator, Data) > 0 do begin
     296function Explode(Separator: Char; Data: string): TStringArray;
     297var
     298  Index: Integer;
     299begin
     300  Result := Default(TStringArray);
     301  repeat
     302    Index := Pos(Separator, Data);
     303    if Index > 0 then begin
     304      SetLength(Result, Length(Result) + 1);
     305      Result[High(Result)] := Copy(Data, 1, Index - 1);
     306      Delete(Data, 1, Index);
     307    end else Break;
     308  until False;
     309  if Data <> '' then begin
    296310    SetLength(Result, Length(Result) + 1);
    297     Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1);
    298     Delete(Data, 1, Pos(Separator, Data));
    299   end;
    300   SetLength(Result, Length(Result) + 1);
    301   Result[High(Result)] := Data;
    302 end;
    303 
    304 {$IFDEF Windows}
     311    Result[High(Result)] := Data;
     312  end;
     313end;
     314
     315{$IFDEF WINDOWS}
    305316function GetUserName: string;
    306317const
     
    310321begin
    311322  L := MAX_USERNAME_LENGTH + 2;
     323  Result := Default(string);
    312324  SetLength(Result, L);
    313325  if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin
     
    323335  end;
    324336end;
    325 {$endif}
     337{$ENDIF}
    326338
    327339function ComputerName: string;
    328 {$ifdef mswindows}
     340{$IFDEF WINDOWS}
    329341const
    330342 INFO_BUFFER_SIZE = 32767;
     
    341353  end;
    342354end;
    343 {$endif}
    344 {$ifdef unix}
     355{$ENDIF}
     356{$IFDEF UNIX}
    345357var
    346358  Name: UtsName;
    347359begin
     360  Name := Default(UtsName);
    348361  fpuname(Name);
    349362  Result := Name.Nodename;
    350363end;
    351 {$endif}
    352 
    353 {$ifdef windows}
     364{$ENDIF}
     365
     366{$IFDEF WINDOWS}
    354367function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    355368const
     
    429442procedure LoadLibraries;
    430443begin
    431   {$IFDEF Windows}
     444  {$IFDEF WINDOWS}
    432445  DLLHandle1 := LoadLibrary('secur32.dll');
    433446  if DLLHandle1 <> 0 then
     
    440453procedure FreeLibraries;
    441454begin
    442   {$IFDEF Windows}
     455  {$IFDEF WINDOWS}
    443456  if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1);
    444457  {$ENDIF}
     
    473486end;
    474487
     488procedure OpenEmail(Email: string);
     489begin
     490  OpenURL('mailto:' + Email);
     491end;
     492
    475493procedure OpenFileInShell(FileName: string);
    476494begin
     
    501519end;
    502520
    503 function MergeArray(A, B: array of string): TArrayOfString;
    504 var
    505   I: Integer;
    506 begin
     521function MergeArray(A, B: array of string): TStringArray;
     522var
     523  I: Integer;
     524begin
     525  Result := Default(TStringArray);
    507526  SetLength(Result, Length(A) + Length(B));
    508527  for I := 0 to Length(A) - 1 do
Note: See TracChangeset for help on using the changeset viewer.