Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Opening files in Delphi

SaMoSaMo Posts: 36Member
Hello all!

I am trying to do the following. Suppose I have a .doc file. So I want my program to launch Word application and open that file. Is there a way to do that in Delphi? I tried WinExec function, but it only opens .exe files, so I can open Word but not the file. Also I did this using TWordApplication component, but it does all the required actions in the background, not showing it on the screen.

Ideally, of course, I would like to have a function that will recognize a type of file and itself choose a program to open this file with. Kind of what Windows does when I click on any file. Is there any way how I can make this?

Any help highly appreciated.

Comments

  • pritaeaspritaeas Posts: 274Member
    Hi. You could try ShellExecute. I'd suggest searching this forum or google for more info on this function (I have no code here with me).

    hth, pritaeas

    : Ideally, of course, I would like to have a function that will
    : recognize a type of file and itself choose a program to open this
    : file with. Kind of what Windows does when I click on any file. Is
    : there any way how I can make this?
  • TiefTief Posts: 179Member
    : Hi. You could try ShellExecute. I'd suggest searching this forum or google for more info on this function (I have no code here with me).
    :
    : hth, pritaeas
    :
    : : Ideally, of course, I would like to have a function that will
    : : recognize a type of file and itself choose a program to open this
    : : file with. Kind of what Windows does when I click on any file. Is
    : : there any way how I can make this?
    :

    Try the TFileRun object in the ExtActns.pas unit. It works great and is easy to use.

    Here's the help

    [code]

    TFileRun is the standard action for performing a specified operation on a file.

    Unit

    ExtActns

    Description

    Add TFileRun to an action list to let your application launch an external application or dll in response to user actions. Controls linked to this action cause your application to perform the operation specified by the Operation property on the file specified by the FileName property.

    Before this action fires, configure its properties to indicate what application to launch and how to launch it:

    To indicate the target file to run, set the FileName property to the name of a file on which the external application operates or to the name of the applications executable file. If you want to let the user select the file name instead when the action fires, set the Browse property to True, and an open dialog appears when the action fires.
    To indicate what action to perform on the specified file, set the Operation property.

    To supply parameters to the external application when it is launched, use the Parameters property.
    To specify a default directory for the external application, use the Directory property.
    To control how the external applications window appears (minimized, maximized, hidden, and so on), use the ShowCmd property.
    If the external application needs a parent window (to parent a dialog such as a properties dialog), or if you want to allow TFileRun to display error messages, use the ParentControl property.

    [/code]

    Happy coding !

    Tief;

  • SaMoSaMo Posts: 36Member
    Hey! Just wanted to say thanks to you guys, you really helped!
Sign In or Register to comment.