delphi7中的访问冲突ShellExecute [英] Access Violation ShellExecute in delphi7
问题描述
我使用ShellExecute的方式与下面相同,在Delphi7中打开一个txt文件,它使我无法访问模块 BORdbk70.dll
。
不知道这是什么问题吗?我在使用列表中添加了 ShellApi
。
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:\text\info.txt';
res := ShellExecute(Handle, nil, PChar(sAddr), nil, nil, SW_SHOW);
showmessage(inttostr(res));
推荐答案
我为您写的这个示例,运行良好(没有错误)。我在Windows 8.1上使用Delphi7进行了测试
This example that I wrote for you, working good (without error). I tested with Delphi7 on Windows 8.1
您必须知道什么是在操作系统中打开* .txt文件的默认应用程序。该应用程序将尝试打开您的文件。在我的* .txt系统上,默认应用程序是Notepad ++,此示例在Notepad ++中打开了文件info.txt
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++
完整源代码(PAS):
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:\text\info.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.
这篇关于delphi7中的访问冲突ShellExecute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!