Howdy, Stranger!

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

Categories

Delphi 7.0 run file onclick

amafatamafat Member Posts: 4
hi im quite new here :),
i would really like to know how to run a file using the OnClick event, example: when i click a button (like that "Post Message" button", i want a certain file on my harddrive to open.
here's my source code if it is to any help. and if it is, where should i put it?
[hr]
[code]
unit JS;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ToolWin, ActnMan, ActnCtrls;

type
TInstall = class(TForm)
ScrollBox1: TScrollBox;
StaticText11: TStaticText;
StaticText10: TStaticText;
StaticText9: TStaticText;
StaticText8: TStaticText;
StaticText7: TStaticText;
StaticText6: TStaticText;
StaticText5: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText2: TStaticText;
Button1: TButton;
Button2: TButton;
StaticText1: TStaticText;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Install: TInstall;

implementation

{$R *.dfm}

procedure TInstall.Button2Click(Sender: TObject);
begin
Install.Close;
end;
procedure TInstall.Button1Click(Sender: TObject);
begin

end;

end.
[/code][hr]
thnx :)

Comments

  • zibadianzibadian Member Posts: 6,349
    : hi im quite new here :),
    : i would really like to know how to run a file using the OnClick event, example: when i click a button (like that "Post Message" button", i want a certain file on my harddrive to open.
    : here's my source code if it is to any help. and if it is, where should i put it?
    : [hr]
    : [code]
    : unit JS;
    :
    : interface
    :
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, StdCtrls, ToolWin, ActnMan, ActnCtrls;
    :
    : type
    : TInstall = class(TForm)
    : ScrollBox1: TScrollBox;
    : StaticText11: TStaticText;
    : StaticText10: TStaticText;
    : StaticText9: TStaticText;
    : StaticText8: TStaticText;
    : StaticText7: TStaticText;
    : StaticText6: TStaticText;
    : StaticText5: TStaticText;
    : StaticText3: TStaticText;
    : StaticText4: TStaticText;
    : StaticText2: TStaticText;
    : Button1: TButton;
    : Button2: TButton;
    : StaticText1: TStaticText;
    : procedure Button2Click(Sender: TObject);
    : private
    : { Private declarations }
    : public
    : { Public declarations }
    : end;
    :
    : var
    : Install: TInstall;
    :
    : implementation
    :
    : {$R *.dfm}
    :
    : procedure TInstall.Button2Click(Sender: TObject);
    : begin
    : Install.Close;
    : end;
    : procedure TInstall.Button1Click(Sender: TObject);
    : begin
    :
    : end;
    :
    : end.
    : [/code][hr]
    : thnx :)
    :
    There are many ways to do this, depending on the type of file. You could use the AssignFile()-Reset()-CloseFile() method, or the windows style FileOpen()-FileClose(), or the TFileStream object. Each of these are described in the help files.
    If you want an external program to open the file you might want to use the ShellExecute() routine.
Sign In or Register to comment.