Changeset 305


Ignore:
Timestamp:
Jan 3, 2012, 10:31:59 AM (13 years ago)
Author:
chronos
Message:
  • Added: Property Finished of TListedThread.
Location:
Common
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r290 r305  
    6161procedure DeleteFiles(APath, AFileSpec: string);
    6262procedure OpenWebPage(URL: string);
     63procedure OpenFileInShell(FileName: string);
     64procedure ExecuteProgram(CommandLine: string);
    6365
    6466
     
    285287  L := MAX_USERNAME_LENGTH + 2;
    286288  SetLength(Result, L);
    287   if Windows.GetUserName(PChar(Result), L) and (L > 0) then
    288     SetLength(Result, StrLen(PChar(Result))) else
    289     Result := '';
     289  if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin
     290    SetLength(Result, StrLen(PChar(Result)));
     291    Result := UTF8Encode(Result);
     292  end else Result := '';
    290293end;
    291294
     
    365368end;
    366369
     370procedure ExecuteProgram(CommandLine: string);
     371var
     372  Process: TProcess;
     373begin
     374  try
     375    Process := TProcess.Create(nil);
     376    Process.CommandLine := CommandLine;
     377    Process.Options := [poNoConsole];
     378    Process.Execute;
     379  finally
     380    Process.Free;
     381  end;
     382end;
     383
    367384procedure OpenWebPage(URL: string);
    368385var
     
    376393    //Process.Executable := Browser;
    377394    //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);
    378     Process.Executable := 'cmd.exe';
    379     Process.Parameters.Add('/c');
    380     Process.Parameters.Add('start');
    381     Process.Parameters.Add(URL);
     395    Process.CommandLine := 'cmd.exe /c start ' + URL;
    382396    Process.Options := [poNoConsole];
    383397    Process.Execute;
     
    387401end;
    388402
     403procedure OpenFileInShell(FileName: string);
     404begin
     405  ExecuteProgram('cmd.exe /c start ' + FileName);
     406end;
    389407
    390408initialization
  • Common/UDebugLog.pas

    r295 r305  
    4545
    4646implementation
     47
     48resourcestring
     49  SFileNameNotDefined = 'Filename not defined';
    4750
    4851procedure Register;
     
    100103  LogFile: TFileStream;
    101104begin
     105  if FileName = '' then raise Exception.Create(SFileNameNotDefined);
    102106  try
    103107    if ExtractFileDir(FileName) <> '' then
     
    131135    TDebugLogItem(List[I]).Free;
    132136  Items.Free;
    133   inherited Destroy;
     137  inherited;
    134138end;
    135139
  • Common/UThreading.pas

    r295 r305  
    1717  TVirtualThread = class
    1818  private
     19    function GetFinished: Boolean; virtual; abstract;
    1920    function GetFreeOnTerminate: Boolean; virtual; abstract;
    2021    function GetPriority: TThreadPriority; virtual; abstract;
     
    4243    property Priority: TThreadPriority read GetPriority write SetPriority;
    4344    property Terminated: Boolean read GetTerminated write SetTerminated;
     45    property Finished: Boolean read GetFinished;
    4446    property ThreadId: Integer read GetThreadId;
    4547  end;
     
    6163  private
    6264    FTerminated: Boolean;
     65    FFinished: Boolean;
    6366    FThread: TListedThreadExecute;
     67    function GetFinished: Boolean; override;
    6468    function GetFreeOnTerminate: Boolean; override;
    6569    function GetPriority: TThreadPriority; override;
     
    172176end;
    173177
    174 
    175178{ TThreadList }
    176179
     
    196199begin
    197200  try
    198     Parent.Execute;
    199   except
    200     on E: Exception do
    201       if Assigned(OnException) then
    202         OnException(Parent.FThread, E);
     201    try
     202      Parent.Execute;
     203    except
     204      on E: Exception do
     205        if Assigned(OnException) then
     206          OnException(Parent.FThread, E);
     207    end;
     208  finally
     209    Parent.FFinished := True;
    203210  end;
    204211end;
    205212
    206213{ TListedThread }
     214
     215function TListedThread.GetFinished: Boolean;
     216begin
     217  Result := FFinished;
     218end;
    207219
    208220function TListedThread.GetFreeOnTerminate: Boolean;
     
    255267  const StackSize: SizeUInt);
    256268begin
     269  FFinished := False;
     270  FTerminated := False;
     271
    257272  FThread := TListedThreadExecute.Create(True, StackSize);
    258273  FThread.Parent := Self;
Note: See TracChangeset for help on using the changeset viewer.