xiongdingfu
xiongdingfu
2017-11-18 04:39

使用ShellExcete打开pdf文件。请问大侠这段程序错误出现在哪儿?该怎么改正确?

10
  • delphi format

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ShellAPI;

type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function TeShuFileName(FFilename: string): string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.TeShuFileName(FFilename: string): string;
var
i:Integer;
s:string;
begin
for i := 1 to Length(FFilename) do
begin
if (FFilename[i]=',') or (FFilename[i]=',') or//路径中逗号
(FFilename[i]='?') or (FFilename[i]='?') or//路径中有问号
(FFilename[i]='《') or (FFilename[i]='《') or //路径中有引号
(FFilename[i]='“ ') or (FFilename[i]='“ ') or //引号
(FFilename[i]='”') or (FFilename[i]='”')
then
s :=s +'"'+FFilename[i]+'"' //加上双引号
else
s :=s+FFilename[i];

end;
FFilename:='"'+FFilename+'"';//路径中有空格
s:=FFilename;
Result :=s;
end;

procedure TForm1.Button1Click(Sender: TObject);//处理文件名中有标点符号,如引号、书名号的情况
var
str:string;
s:string;
begin
if OpenDialog1.Execute then
begin
str:=OpenDialog1.FileName;
end;
str:=TeShuFileName(str);
s:=Format('/e,/select,%s',[str]);//format的用法
s:='"'+s+'"';//处理带空格的情况
ShellExecute(0, 'open', 'AcroRd32.exe', PChar(s), '', SW_SHOWMAXIMIZED);

end;

end.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答