【发布时间】:2015-10-13 23:43:57
【问题描述】:
我将我的程序添加到了 SendTo。我向它发送了两个文件。 它们是:
C:\ThisIsMySuperTestHelloWorld\ThisBookIsRedMyPenIsWhite\test.jpg
C:\ThisIsMySuperTestHelloWorld\ThisBookIsRedMyPenIsWhite\hello.jpg
下面的代码显示C:\ThisIsMySuperTestHelloWorld\ThisBookIsRedMyPenIsWhite\test.jpg@C:\ThisIsMySuperTestHelloWorld\ThisBookIsRedMyPenIsWhite\test.jpg
procedure TForm1.FormCreate(Sender: TObject);
var Files: array of PAnsiChar;
i: Integer;
begin
SetLength(Files, 2);
for i:=0 to 1 do begin
Files[i] := PAnsiChar(ParamStr(2+i));
end;
ShowMessage( Files[0] +'@' + Files[1] );
end;
我在 Windows7 上使用 Delphi 6。 在 Delphi Xe3(仍然是 Win7)下,我将(两者)PAnsiChar 更改为 PWideChar,效果相同。
我的 SendTo 链接链接到:
"C:\<PATH_HERE>\Project1.exe" c
并放置在这里:
C:\Users\<USER>\AppData\Roaming\Microsoft\Windows\SendTo
【问题讨论】:
-
你可以使用
PChar而不是PAnsiChar/PWideChar来添加更多的魔法,现在不管你用Delphi 6还是Delphi XE3编译都没有关系 -
在编程方面,没有魔法这回事。这实际上是当今的问题 - 太多人认为软件背后存在某种巫术。
-
请阅读this article about using PChar and strings。正如其他人已经注意到的那样,在这里使用 PChars 并不是一个好主意。