Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Wie wirsam Exception abfangen (https://www.delphipraxis.net/146241-wie-wirsam-exception-abfangen.html)

marcos 16. Jan 2010 12:06


Wie wirsam Exception abfangen
 
Hallo,

ich habe ein Problem, dass meine Exe einfach verschwindet ohne irgendwelche Fehlermeldung.
Das merkwürdige daran: das habe ich nur auf einem PC bis jetzt festgestellt und nur bei einer Datei C:\WINDOWS\system32\userinit.exe.
Gibt es eine Möglichkeit den Fehler wirksam abzufangen? Kann jemand das Problem nachvollziehen?

Gruß
marcos

P.S.
MadExcept hilft nichts.


Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellApi;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure ShowShellPropertiesDlg(const APath: string);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
   Edit1.Text := 'C:\WINDOWS\system32\userinit.exe';
   try
     ShowShellPropertiesDlg(Edit1.Text);
   except
      MessageBox(Handle, 'Exception', 'Test', 0);
   end;
end;


procedure TForm1.ShowShellPropertiesDlg(const APath: string);
var
  AExecInfo: ShellAPI.TShellExecuteinfo; // info passed to ShellExecuteEx
begin
  FillChar(AExecInfo, SizeOf(AExecInfo), 0);
  AExecInfo.cbSize := SizeOf(AExecInfo);
  AExecInfo.lpFile := PChar(APath);
  AExecInfo.lpVerb := 'properties';
  AExecInfo.fMask := ShellAPI.SEE_MASK_INVOKEIDLIST;
  ShellAPI.ShellExecuteEx(@AExecInfo); //<----------------- EXE weg!!!!
end;


end.

sx2008 16. Jan 2010 14:26

Re: Wie wirsam Exception abfangen
 
versuch mal die Funktion:
Delphi-Quellcode:
function DisplayPropDialog(const Handle: THandle; const FileName: string): Boolean;
var
  Info: TShellExecuteInfo;
begin
  FillChar(Info, SizeOf(Info), #0);
  with Info do
  begin
    cbSize := SizeOf(Info);
    lpFile := PChar(FileName);
    nShow := SW_SHOW;
    fMask := SEE_MASK_INVOKEIDLIST;
    Wnd := Handle;
    lpVerb := cVerbProperties;
  end;
  Result := ShellExecuteEx(@Info);
end;
Das Handle ist dein Fensterhandle:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  filename : string;
begin
   filename := 'C:\WINDOWS\system32\userinit.exe';
   if not DisplayPropDialog(Handle, filename) then
     RaiseLastWin32Error;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:34 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz