Changeset 557 for Common


Ignore:
Timestamp:
Feb 15, 2022, 10:14:04 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r556 r557  
    1313type
    1414  TArrayOfByte = array of Byte;
    15   TArrayOfString = array of string;
    1615  TExceptionEvent = procedure(Sender: TObject; E: Exception) of object;
    1716
     
    5150function ComputerName: string;
    5251procedure DeleteFiles(APath, AFileSpec: string);
     52function Explode(Separator: Char; Data: string): TStringArray;
    5353procedure ExecuteProgram(Executable: string; Parameters: array of string);
    5454procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
     
    6565function LoadFileToStr(const FileName: TFileName): AnsiString;
    6666function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    67 function MergeArray(A, B: array of string): TArrayOfString;
     67function MergeArray(A, B: array of string): TStringArray;
    6868function OccurenceOfChar(What: Char; Where: string): Integer;
    6969procedure OpenWebPage(URL: string);
     
    291291end;
    292292
    293 function Explode(Separator: char; Data: string): TArrayOfString;
    294 begin
    295   Result := nil;
    296   SetLength(Result, 0);
    297   while Pos(Separator, Data) > 0 do begin
     293function Explode(Separator: Char; Data: string): TStringArray;
     294var
     295  Index: Integer;
     296begin
     297  Result := Default(TStringArray);
     298  repeat
     299    Index := Pos(Separator, Data);
     300    if Index > 0 then begin
     301      SetLength(Result, Length(Result) + 1);
     302      Result[High(Result)] := Copy(Data, 1, Index - 1);
     303      Delete(Data, 1, Index);
     304    end else Break;
     305  until False;
     306  if Data <> '' then begin
    298307    SetLength(Result, Length(Result) + 1);
    299     Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1);
    300     Delete(Data, 1, Pos(Separator, Data));
    301   end;
    302   SetLength(Result, Length(Result) + 1);
    303   Result[High(Result)] := Data;
    304 end;
    305 
    306 {$IFDEF Windows}
     308    Result[High(Result)] := Data;
     309  end;
     310end;
     311
     312{$IFDEF WINDOWS}
    307313function GetUserName: string;
    308314const
     
    312318begin
    313319  L := MAX_USERNAME_LENGTH + 2;
     320  Result := Default(string);
    314321  SetLength(Result, L);
    315322  if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin
     
    325332  end;
    326333end;
    327 {$endif}
     334{$ENDIF}
    328335
    329336function ComputerName: string;
    330 {$ifdef mswindows}
     337{$IFDEF WINDOWS}
    331338const
    332339 INFO_BUFFER_SIZE = 32767;
     
    343350  end;
    344351end;
    345 {$endif}
    346 {$ifdef unix}
     352{$ENDIF}
     353{$IFDEF UNIX}
    347354var
    348355  Name: UtsName;
     
    352359  Result := Name.Nodename;
    353360end;
    354 {$endif}
    355 
    356 {$ifdef windows}
     361{$ENDIF}
     362
     363{$IFDEF WINDOWS}
    357364function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    358365const
     
    432439procedure LoadLibraries;
    433440begin
    434   {$IFDEF Windows}
     441  {$IFDEF WINDOWS}
    435442  DLLHandle1 := LoadLibrary('secur32.dll');
    436443  if DLLHandle1 <> 0 then
     
    443450procedure FreeLibraries;
    444451begin
    445   {$IFDEF Windows}
     452  {$IFDEF WINDOWS}
    446453  if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1);
    447454  {$ENDIF}
     
    509516end;
    510517
    511 function MergeArray(A, B: array of string): TArrayOfString;
    512 var
    513   I: Integer;
    514 begin
    515   Result := Default(TArrayOfString);
     518function MergeArray(A, B: array of string): TStringArray;
     519var
     520  I: Integer;
     521begin
     522  Result := Default(TStringArray);
    516523  SetLength(Result, Length(A) + Length(B));
    517524  for I := 0 to Length(A) - 1 do
Note: See TracChangeset for help on using the changeset viewer.