zoukankan      html  css  js  c++  java
  • 启动程序的同时传参给接收程序(XE8+WIN764)

    相关资料:

    http://blog.csdn.net/yanjiaye520/article/details/7590252

    注意事项:

    1.ParamStr(0)是实例自己。

    2.传的参数是以空格分看的。

    3.“‘2 Hello World”,ParamStr(1) = '2' ;

    发送窗体:

     1 unit Unit1;
     2 
     3 interface
     4 
     5 uses
     6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
     7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ShellAPI, Vcl.StdCtrls;
     8 
     9 type
    10   TForm1 = class(TForm)
    11     Button1: TButton;
    12     procedure Button1Click(Sender: TObject);
    13   private
    14     { Private declarations }
    15   public
    16 
    17     { Public declarations }
    18   end;
    19 
    20 var
    21   Form1: TForm1;
    22 
    23 implementation
    24 
    25 {$R *.dfm}
    26 
    27 procedure TForm1.Button1Click(Sender: TObject);
    28 begin
    29   ShellExecute(Handle, 'open','project2.exe','2 Hello World',nil,SW_SHOWNORMAL);
    30 end;
    31 
    32 end.
    View Code

    接收窗体:

     1 unit Unit1;
     2 
     3 interface
     4 
     5 uses
     6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
     7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
     8 
     9 type
    10   TForm1 = class(TForm)
    11     ListBox1: TListBox;
    12     Label1: TLabel;
    13     procedure FormCreate(Sender: TObject);
    14   private
    15     { Private declarations }
    16   public
    17     { Public declarations }
    18   end;
    19 
    20 var
    21   Form1: TForm1;
    22 
    23 implementation
    24 
    25 {$R *.dfm}
    26 
    27 procedure TForm1.FormCreate(Sender: TObject);
    28 begin
    29   //ParamStr(0)是实例自己,所以参数从1开始;而且传的参数是以空格分看的,“‘2 Hello World”,ParamStr(1) = '2' 了;
    30   ListBox1.Items.Add(ParamStr(1));
    31 end;
    32 
    33 end.
    View Code

    PS:如果使用CreateProcess建进程,怎么发参数呢?

     1     if not IsBuildInFit then
     2     begin //不代参数
     3       bActiveState := CreateProcess(PChar(nil), PChar(GetExePath + sHardWareName), @lpsaProcess,
     4               @lpsaThread, false, CREATE_SHARED_WOW_VDM, PChar(nil), PChar(nil),
     5               lpsiStartInfo, oProcInfo);
     6     end
     7     else
     8     begin //代参数
     9       bActiveState := CreateProcess(PChar(nil), PChar(GetExePath + sHardWareName + ' True'), @lpsaProcess,
    10               @lpsaThread, false, CREATE_SHARED_WOW_VDM, PChar(nil), PChar(nil),
    11               lpsiStartInfo, oProcInfo);
    12     end;
  • 相关阅读:
    第 4 章 容器
    第 4 章 容器
    第 4 章 容器
    第 4 章 容器
    第 3 章 镜像
    第 3 章 镜像
    seekbar拖动条控件
    OnClick,onLongClick,OnTouch调用机制
    在TextView文本中实现activity跳转
    TextView显示html图片方法
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/5953631.html
Copyright © 2011-2022 走看看