-1

I am using Delphi 6 (yes, I know, but I am old school).

I have a problem with TShellExecuteInfo. I want to run this command: C:\delphi\bin\Convert.exe -b-i plus a paramstring (folder and name of file).

If I put the -b-i after the Executeinfo.lpfile then ShellExecuteEx() can't find Convert.exe, and if I put it in Paramstring then Convert.exe can't find the file.

I have spend 3 days on this, so I hope you can help.

BTW, why would Delphi suddenly start to save my file as text?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Pthanner
  • 13
  • 5

1 Answers1

3

You should not be using ShellExecuteEx() for this at all. That function is meant for executing document files, not running applications. You should be using CreateProcess() instead. Simply past the whole command to its lpCommandLine parameter, eg:

procedure ConvertFile(const FileName: string);
var
  Cmd: string;
  Si: TStartupInfo;
  Pi: TProcessInformation;
begin
  Cmd := 'C:\delphi\bin\Convert.exe -b -i ' + AnsiQuotedStr(FileName, '"'); 

  ZeroMemory(@Si, Sizeof(Si));
  Si.cb := Sizeof(Si);

  if not CreateProcess(nil, PChar(Cmd), nil, nil, False, 0, nil, nil, Si, Pi) then
    RaiseLastOSError;
  try
    //...
  finally
    CloseHandle(Pi.hThread);
    CloseHandle(Pi.hProcess);
  end;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you Remy Weel at least covert is running now but it don't convert anything – Pthanner May 09 '19 at 10:00
  • 1
    @user2844963 This answer solves the question as it was asked. As to why nothing actually happens, that's a separate issue that requires a separate question. – Jerry Dodge May 09 '19 at 13:02
  • @user2844963 need more information. What is the actual filename that you are passing to it? What format is that file in before the conversion? – Remy Lebeau May 09 '19 at 14:21
  • @Remy Lebeau The file I am sending it is a Delphi form (.dfm) that for some reason have been saved as text, so I can only open it as text and not manipulate thecomponent as you normally would – Pthanner May 10 '19 at 23:29
  • That can happen if you open the DFM itself, instead of opening the unit that the DFM belongs to. Open the unit in the IDE, and then you should be able to open the Form Designer and modify the DFM as needed. If needed, you can right-click on the Form Designer and choose the format for the DFM to be saved as to file (Text vs Binary). – Remy Lebeau May 10 '19 at 23:31