Ignore:
Timestamp:
Apr 25, 2022, 6:22:53 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Update Common package to version 0.10.
  • Modified: fgl unit replaced by Generics.Collections.
File:
1 edited

Legend:

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

    r423 r424  
    66  {$IFDEF WINDOWS}Windows,{$ENDIF}
    77  {$IFDEF UNIX}baseunix,{$ENDIF}
    8   Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
     8  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, Graphics,
    99  FileUtil; //, ShFolder, ShellAPI;
    1010
    1111type
    1212  TArrayOfByte = array of Byte;
    13   TArrayOfString = array of string;
    1413  TExceptionEvent = procedure(Sender: TObject; E: Exception) of object;
    1514
     
    3332  DLLHandle1: HModule;
    3433
    35 {$IFDEF WINDOWS}
    36   GetUserNameEx: procedure (NameFormat: DWORD;
    37     lpNameBuffer: LPSTR; nSize: PULONG); stdcall;
    38 {$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);
    3943
    4044function AddLeadingZeroes(const aNumber, Length : integer) : string;
     
    4953function ComputerName: string;
    5054procedure DeleteFiles(APath, AFileSpec: string);
     55function Explode(Separator: Char; Data: string): TStringArray;
    5156procedure ExecuteProgram(Executable: string; Parameters: array of string);
    5257procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
     
    6368function LoadFileToStr(const FileName: TFileName): AnsiString;
    6469function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    65 function MergeArray(A, B: array of string): TArrayOfString;
     70function MergeArray(A, B: array of string): TStringArray;
    6671function OccurenceOfChar(What: Char; Where: string): Integer;
    6772procedure OpenWebPage(URL: string);
     73procedure OpenEmail(Email: string);
    6874procedure OpenFileInShell(FileName: string);
    6975function PosFromIndex(SubStr: string; Text: string;
     
    8187function SplitString(var Text: string; Count: Word): string;
    8288function StripTags(const S: string): string;
    83 function TryHexToInt(Data: string; var Value: Integer): Boolean;
    84 function TryBinToInt(Data: string; var Value: Integer): Boolean;
     89function TryHexToInt(Data: string; out Value: Integer): Boolean;
     90function TryBinToInt(Data: string; out Value: Integer): Boolean;
    8591procedure SortStrings(Strings: TStrings);
    8692
     
    244250end;
    245251
    246 function TryHexToInt(Data: string; var Value: Integer): Boolean;
     252function TryHexToInt(Data: string; out Value: Integer): Boolean;
    247253var
    248254  I: Integer;
     
    260266end;
    261267
    262 function TryBinToInt(Data: string; var Value: Integer): Boolean;
     268function TryBinToInt(Data: string; out Value: Integer): Boolean;
    263269var
    264270  I: Integer;
     
    288294end;
    289295
    290 function Explode(Separator: char; Data: string): TArrayOfString;
    291 begin
    292   SetLength(Result, 0);
    293   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
    294310    SetLength(Result, Length(Result) + 1);
    295     Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1);
    296     Delete(Data, 1, Pos(Separator, Data));
    297   end;
    298   SetLength(Result, Length(Result) + 1);
    299   Result[High(Result)] := Data;
     311    Result[High(Result)] := Data;
     312  end;
    300313end;
    301314
     
    308321begin
    309322  L := MAX_USERNAME_LENGTH + 2;
     323  Result := Default(string);
    310324  SetLength(Result, L);
    311325  if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin
     
    344358  Name: UtsName;
    345359begin
     360  Name := Default(UtsName);
    346361  fpuname(Name);
    347362  Result := Name.Nodename;
     
    471486end;
    472487
     488procedure OpenEmail(Email: string);
     489begin
     490  OpenURL('mailto:' + Email);
     491end;
     492
    473493procedure OpenFileInShell(FileName: string);
    474494begin
     
    499519end;
    500520
    501 function MergeArray(A, B: array of string): TArrayOfString;
    502 var
    503   I: Integer;
    504 begin
     521function MergeArray(A, B: array of string): TStringArray;
     522var
     523  I: Integer;
     524begin
     525  Result := Default(TStringArray);
    505526  SetLength(Result, Length(A) + Length(B));
    506527  for I := 0 to Length(A) - 1 do
Note: See TracChangeset for help on using the changeset viewer.