Ignore:
Timestamp:
Oct 27, 2016, 3:00:47 PM (8 years ago)
Author:
chronos
Message:
  • Added: Remember position and size of main form after close of application.
  • Modified: Updated Common package to latest version.
File:
1 edited

Legend:

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

    r72 r73  
    88  {$IFDEF Windows}Windows,{$ENDIF}
    99  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
    10   FileUtil, LazFileUtils; //, ShFolder, ShellAPI;
     10  FileUtil; //, ShFolder, ShellAPI;
    1111
    1212type
     
    6464procedure ExecuteProgram(CommandLine: string);
    6565procedure FreeThenNil(var Obj);
     66function RemoveQuotes(Text: string): string;
     67function ComputerName: string;
     68function OccurenceOfChar(What: Char; Where: string): Integer;
     69function GetDirCount(Dir: string): Integer;
     70function MergeArray(A, B: array of string): TArrayOfString;
    6671
    6772
     
    9196  I: Integer;
    9297begin
    93   Result := '';
    9498  for I := 1 to Length(Source) do begin
    9599    Result := Result + LowerCase(IntToHex(Ord(Source[I]), 2));
     
    106110  Path := IncludeTrailingPathDelimiter(APath);
    107111
    108   Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec);
     112  Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);
    109113  while Find = 0 do begin
    110     DeleteFileUTF8(Path + SearchRec.Name);
     114    DeleteFile(Path + UTF8Encode(SearchRec.Name));
    111115
    112116    Find := SysUtils.FindNext(SearchRec);
     
    287291  L: LongWord;
    288292begin
    289 
    290293  L := MAX_USERNAME_LENGTH + 2;
    291294  SetLength(Result, L);
     
    302305  end;
    303306end;
     307
     308function ComputerName: string;
     309{$ifdef mswindows}
     310const
     311 INFO_BUFFER_SIZE = 32767;
     312var
     313  Buffer : array[0..INFO_BUFFER_SIZE] of WideChar;
     314  Ret : DWORD;
     315begin
     316  Ret := INFO_BUFFER_SIZE;
     317  If (GetComputerNameW(@Buffer[0],Ret)) then begin
     318    Result := UTF8Encode(WideString(Buffer));
     319  end
     320  else begin
     321    Result := 'ERROR_NO_COMPUTERNAME_RETURNED';
     322  end;
     323end;
     324{$endif}
     325{$ifdef unix}
     326begin
     327  Result := GetHostName;
     328end;
     329{$endif}
    304330
    305331function LoggedOnUserNameEx(Format: TUserNameFormat): string;
     
    417443
    418444procedure OpenWebPage(URL: string);
     445var
     446  Process: TProcess;
     447  Browser, Params: string;
    419448begin
    420449  OpenURL(URL);
     450  {try
     451    Process := TProcess.Create(nil);
     452    Browser := '';
     453    //FindDefaultBrowser(Browser, Params);
     454    //Process.Executable := Browser;
     455    //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);
     456    Process.CommandLine := 'cmd.exe /c start ' + URL;
     457    Process.Options := [poNoConsole];
     458    Process.Execute;
     459  finally
     460    Process.Free;
     461  end;}
    421462end;
    422463
     
    426467end;
    427468
     469function RemoveQuotes(Text: string): string;
     470begin
     471  Result := Text;
     472  if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then
     473    Result := Copy(Text, 2, Length(Text) - 2);
     474end;
     475
     476function OccurenceOfChar(What: Char; Where: string): Integer;
     477var
     478  I: Integer;
     479begin
     480  Result := 0;
     481  for I := 1 to Length(Where) do
     482    if Where[I] = What then Inc(Result);
     483end;
     484
     485function GetDirCount(Dir: string): Integer;
     486begin
     487  Result := OccurenceOfChar(DirectorySeparator, Dir);
     488  if Copy(Dir, Length(Dir), 1) = DirectorySeparator then
     489    Dec(Result);
     490end;
     491
     492function MergeArray(A, B: array of string): TArrayOfString;
     493var
     494  I: Integer;
     495begin
     496  SetLength(Result, Length(A) + Length(B));
     497  for I := 0 to Length(A) - 1 do
     498    Result[I] := A[I];
     499  for I := 0 to Length(B) - 1 do
     500    Result[Length(A) + I] := B[I];
     501end;
     502
     503
     504
    428505initialization
    429506
Note: See TracChangeset for help on using the changeset viewer.