// aus dem SwissDelphiCenter:
function ShellExecuteAndWait(Operation, FileName, Parameter, Directory:
string; Show: Word;
bWait: Boolean): LongInt;
var
bOK: Boolean;
ShExecInfo: TShellExecuteInfo;
begin
FillChar(ShExecInfo, SizeOf(ShExecInfo), Chr(0));
ShExecInfo.cbSize := SizeOf(ShExecInfo);
ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.lpVerb := PChar(Operation);
ShExecInfo.lpFile := PChar(FileName);
ShExecInfo.lpParameters := PChar(Parameter);
ShExecInfo.lpDirectory := PChar(Directory);
ShExecInfo.nShow := Show;
bOK := Boolean(ShellExecuteEx(@ShExecInfo));
if bOK
then
begin
if bWait
then
begin
while WaitForSingleObject(ShExecInfo.hProcess, 100) = WAIT_TIMEOUT
do
Application.ProcessMessages;
bOK := GetExitCodeProcess(ShExecInfo.hProcess, DWORD(Result));
end
else
Result := 0;
end;
if not bOK
then
Result := -1;
end;
procedure TFrmMain.acCodeFormatterExecute(Sender: TObject);
var
TempFile:
string;
ConfigFile:
string;
begin
Screen.Cursor := crHourGlass;
try
TempFile := GetEnvironmentVariable('
temp') + PathDelim + '
Temp.pas';
ConfigFile := '
Formatter.config';
SynMemo1.Lines.SaveToFile(TempFile);
if ShellExecuteAndWait('
open', ExtractFilePath(Application.ExeName) + '
Formatter.exe',
'
-delphi -config ' + ConfigFile + '
' + TempFile, ParamStr(0), SW_HIDE, True) = 0
then
SynMemo1.Lines.LoadFromFile(TempFile)
else
raise SysUtils.Exception.Create('
Es ist ein Fehler beim Formatieren aufgetreten.' + #13#10 +
'
Wenden Sie sich bitte an ihren IT-Koordinator.');
// ShellExecute(Handle, 'open', PChar(ExtractFilePath(Application.ExeName) + 'Formatter.exe'),
// PChar(' -delphi -config ' + ConfigFile + ' ' + TempFile), nil, SW_HIDE);
// Sleep(1000);
// SynMemo1.Lines.LoadFromFile(TempFile);
finally
Screen.Cursor := crDefault;
end;
end;