Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

shell - Access Violation ShellExecute in delphi7

I am using ShellExecute the same way given below, to open a txt file in Delphi7, it gives me access violation in module BORdbk70.dll. Not sure what this issue is? I have added ShellApi in uses list.

//sAddr := 'www.google.com'; 
Above line does not gives any error but also not redirect to browser and 
  ShellExecute returns result as "5 = Windows 95 only: The operating system denied access to the specified file"

sAddr := 'c:	extinfo.txt';
res := ShellExecute(Handle, nil, PChar(sAddr), nil, nil, SW_SHOW);
showmessage(inttostr(res));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This example that I wrote for you, working good (without error). I tested with Delphi7 on Windows 8.1

You must know what is default application to open *.txt files in your Operation System. That application will try open your file. On my system for *.txt default application is Notepad++ and this example opened file info.txt in Notepad++

Full source (pas) code:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellApi;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  sAddr : String;
  res : Integer;
begin
  sAddr := 'c:	extinfo.txt';
  res := ShellExecute(Handle, 'open', PChar(sAddr), nil, nil, SW_SHOW);
  showmessage(inttostr(res));
end;
end.

This example working good with admin and normal user rights.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...