Recent

Author Topic: opening file from external program  (Read 4660 times)

polpero

  • Full Member
  • ***
  • Posts: 127
opening file from external program
« on: January 02, 2015, 06:08:20 pm »
Hi

I have created a small Html help viewer (HViewer.exe)
I know how to call and open it with TProcess
but I can't find out how to have it open a specific file...

should I use the TProcess.parameters?

must HViewer.exe be explicitely instructed that it can open the sent files?

Thanks!

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: opening file from external program
« Reply #1 on: January 02, 2015, 06:20:17 pm »
Code: [Select]
OpenDocument(Filename :string).

polpero

  • Full Member
  • ***
  • Posts: 127
Re: opening file from external program
« Reply #2 on: January 02, 2015, 06:43:10 pm »
nope...

I don't want the file to open in the default browser...
I want it to open in that HViewer.exe

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: opening file from external program
« Reply #3 on: January 02, 2015, 06:47:36 pm »
must HViewer.exe be explicitely instructed that it can open the sent files?
Yes

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: opening file from external program
« Reply #4 on: January 03, 2015, 02:53:46 pm »
How does your HViewer "know" which file to open?

Typically for such purposes a commandline parameter can be passed (see ParamCount/ParamStrUtf8() ).
If HViewer can handle that (commandline parameters), then you in your calling program you can add the filename to TProcess.Parameters.

Bart

polpero

  • Full Member
  • ***
  • Posts: 127
Re: opening file... Solution recap
« Reply #5 on: January 03, 2015, 06:55:40 pm »
Yes everything works fine now. Thanks for your hints and suggestions.
Here is how I figure it out.

The file is sent in the caller app:

  ...
  fName := filePath + '\filename.htm';
  AProcess := TProcess.Create(nil);
  AProcess.Executable:= 'HTMView.exe';
  //AProcess.CommandLine := 'HTMView.exe '+ fName ;
  AProcess.Parameters.Add(fName);
  ...


Then on HTMViewer.onShow I've got

  ...
  with application do
    //showMessage(intToStr(paramCount));
    if (paramCount > 0) then
      begin
       if fileExists( Params[1] ) then
           doLoadFile( pChar(params[1]));
       exit;
      end;
    ...


Thanks

 

TinyPortal © 2005-2018