Home > Back-end >  In the file contains a comma, quotation marks, question marks, quotation marks, how to open the PDF
In the file contains a comma, quotation marks, question marks, quotation marks, how to open the PDF

Time:09-17

The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ShellAPI StrUtils;

Type
TForm1=class (TForm)
OpenDialog1: TOpenDialog;
Button2: TButton;
Procedure Button2Click (Sender: TObject);
Private
{Private declarations}

Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}


Procedure TForm1. Button2Click (Sender: TObject);
Var
S: a string;
The begin
If OpenDialog1. Execute then
The begin
S:=OpenDialog1. FileName;
end;

//handle file path with a question mark, comma
S:=AnsiReplaceText (s, '? ', '"?" ');//question mark
S:=AnsiReplaceText (s, 'and', '", ");//comma
S:=AnsiReplaceText (s, 'and', '", ");//comma

S:='"' + + 's "';//handle with space
the condition of theShellExecute (0, the 'open', 'AcroRd32. Exe, PChar (s),' ', SW_SHOWMAXIMIZED);

end;

End.

Why can appear the following error after the program is run?

CodePudding user response:

1, save the file, in the name of the file as much as possible, do not use special characters;
2, the name of the file (Chinese double byte) have symbols, directly from the original file name can be opened, when

Your problem is, when open the file, the original filename in the double byte symbol, for a single character symbols, modify the name of the file, open a non-existent file mistakes,

CodePudding user response:

 
Procedure TForm1. Button2Click (Sender: TObject);
Var s: a string;
The begin
If OpenDialog1. Execute then
The begin
ShellExecute (0, the 'open', 'AcroRd32. Exe, PChar (OpenDialog1. FileName),' ', SW_SHOWMAXIMIZED);
END;
end;
  • Related