• 启动程序的同时传参给接收程序(XE8+WIN764)


    启动程序的同时传参给接收程序(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.
    复制代码

    接收窗体:

    复制代码
     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.
    复制代码

    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;
    复制代码
    QQ:513187410 朱建强 PS:代码随意使用,如出现法律问题,与本人无关。
  • 相关阅读:
    ruby中nil?, empty? and blank?
    dialog插件demo
    Oauth2.0 QQ&微信&微博实现第三方登陆
    SSM框架应用
    点击<a>标签后禁止页面跳至顶部
    使用Node.js+Hexo+Github搭建个人博客(续)
    软件项目托管平台
    【转载】 Eclipse注释模板设置详解
    Markdown 简介及基础语法
    SpringMVC简介
  • 原文地址:https://www.cnblogs.com/westsoft/p/5962281.html
Copyright © 2020-2023  润新知