Recent

Author Topic: Loading a file accourding to the default program  (Read 11685 times)

captian jaster

  • Guest
Loading a file accourding to the default program
« on: December 27, 2010, 01:30:18 am »
How can I open a file with the default program it set to in windows..?(Hope I'm not being confusing.)  :(
« Last Edit: December 27, 2010, 02:33:09 am by captain jaster »

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Loading a file accourding to the default program
« Reply #1 on: December 27, 2010, 07:30:39 am »
uses
 ...process
.....
var
  my_pipe : TProcess;
begin
  //proccess
  my_pipe:=TProcess.Create(nil);
  my_pipe.CommandLine:=cmd_value+' my_file';('firefox my.html' :sample)
  my_pipe.Options:=[poUsePipes];
  my_pipe.Execute;
  my_pipe.Free;


p.s. work well(linux, win) ;)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946

captian jaster

  • Guest
Re: Loading a file accourding to the default program
« Reply #3 on: December 27, 2010, 08:55:39 pm »
http://lazarus-ccr.sourceforge.net/docs/lcl/lclintf/opendocument.html
It wouldn't find the procedure..

uses
 ...process
.....
var
  my_pipe : TProcess;
begin
  //proccess
  my_pipe:=TProcess.Create(nil);
  my_pipe.CommandLine:=cmd_value+' my_file';('firefox my.html' :sample)
  my_pipe.Options:=[poUsePipes];
  my_pipe.Execute;
  my_pipe.Free;


p.s. work well(linux, win) ;)
It didn't find cmd_Value

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: Loading a file accourding to the default program
« Reply #4 on: December 27, 2010, 09:40:44 pm »
It wouldn't find the procedure..
...
It didn't find cmd_Value

are you kidding us?  :D

seba22

  • Full Member
  • ***
  • Posts: 136
Re: Loading a file accourding to the default program
« Reply #5 on: December 27, 2010, 10:02:10 pm »
Don't kill if i'm wrong but in windows you can try.

  my_pipe.CommandLine:='explorer.exe c:\myfile.html';

explorer.exe should pass that myfile.html for default application.

Code: [Select]
explorer.exe c:\a.bmp should run paint, with a.bmp loaded.

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Loading a file accourding to the default program
« Reply #6 on: December 27, 2010, 10:11:31 pm »
It wouldn't find the procedure..
...
It didn't find cmd_Value

are you kidding us?  :D
Probably not... OpenDocument is not available in LCL 0.9.28.2 and lower and for TProcess you still need the full path of the executable (and cmd_Value is *not* defined in the code that was posted!).

For Windows you could use ShellExecute (unit Windows):
Code: [Select]
ShellExecute(0, 'open', 'filename', '', nil, SW_SHOWNORMAL);
Gr.
Dirk.

captian jaster

  • Guest
Re: Loading a file accourding to the default program
« Reply #7 on: December 27, 2010, 10:27:32 pm »
It wouldn't find the procedure..
...
It didn't find cmd_Value

are you kidding us?  :D
Probably not... OpenDocument is not available in LCL 0.9.28.2 and lower and for TProcess you still need the full path of the executable (and cmd_Value is *not* defined in the code that was posted!).

For Windows you could use ShellExecute (unit Windows):
Code: [Select]
ShellExecute(0, 'open', 'filename', '', nil, SW_SHOWNORMAL);
Gr.
Don't kill if i'm wrong but in windows you can try.

  my_pipe.CommandLine:='explorer.exe c:\myfile.html';

explorer.exe should pass that myfile.html for default application.

Code: [Select]
explorer.exe c:\a.bmp should run paint, with a.bmp loaded.
Dirk.

Both of these codes work..
But the WinShell one is faster..
With the explorer.exe it takes a second before it loads up..

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Loading a file accourding to the default program
« Reply #8 on: December 28, 2010, 07:27:39 am »
Just set path(control panel, advanced, environment path), add(sample) c:\Program Files\your_exe.
Name of exe is cmd_value(without '.exe'), batch command.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Loading a file accourding to the default program
« Reply #9 on: December 28, 2010, 04:15:33 pm »
WinShell: Is cross platform?

OpenDocument: Can launch an application like (for example) "solitaire.exe" without get stuck until "solitaire.exe" is closed?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Loading a file accourding to the default program
« Reply #10 on: December 28, 2010, 04:21:58 pm »
Yes.

ShellExecute is for Windows only.
« Last Edit: December 28, 2010, 04:23:48 pm by typo »

 

TinyPortal © 2005-2018