向exe文件传递参数 在线等待答案(20分)

S

saga

Unregistered / Unconfirmed
GUEST, unregistred user!
请问程序中如何写,才能向exe文件传递参数。
比如program是一个exe文件,string是一个参数
Program String 就可以把string参数带到程序program里面?
谢谢
 
1、利用命令行传递
2、利用剪切板传递
3、利用DDE通过内存传递
4、利用外部文件如INI或TXT文件进行传递
 
使用ParamStr获得参数, 而ParamCount则可以返回有多少个参数, 以下是Delphi
关于这两个函数的说明,Delphi帮助对这两个函数都有例子

function ParamStr(Index: Integer): string;
Description
ParamStr returns the parameter from the command line that corresponds
to Index, or an empty string if Index is greater than ParamCount.
For example, an Index value of 2 returns the second command-line parameter.
ParamStr(0) returns the path and file name of the executing program
(for example, C:/TEST/MYPROG.EXE).

function ParamCount: Integer;
Description
ParamCount returns the number of parameters passed to the program on
the command line. Separate parameters with spaces or tabs. Use double
uotes to wrap multiple words as one parameter (such as long file names
containing spaces).
 
procedure TForm1.FormCreate(Sender: TObject);

var
i: Integer;
for i := 0 to ParamCount -1 do
begin
if LowerCase(ParamStr(i)) = 'beep' then
Beep(10000,1000) //或者设置系统变量
else if (LowerCase(ParamStr(i)) = 'exit' then
Application.Terminate;
end;
end;
 
program.exe 是不是你写的呢?
是的话,用命令行参数就可以了。
不是的话,要想别的办法了。
比如:sendmessage等
 
有此EXE文件在打開過程中的參數直接在程序名後加個空格再
加入參數名稱就可以了,要注意單引號的使用
 
多人接受答案了。
 
顶部