zoukankan      html  css  js  c++  java
  • 启动程序的同时传参给接收程序(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:代码随意使用,如出现法律问题,与本人无关。
  • 相关阅读:
    [TC_SRM_466]DrawingBlackCrosses
    [POJ3254]Corn Fields
    [openjudge6043]哆啦A梦的时光机
    网络流 24 题汇总(LOJ 上只有 22 题???)
    Xadmin组件的url设计
    《今日简史》一、旧故事已然崩坏,新故事尚未构建
    《人类简史》二、认知革命——上帝之手的秘密
    ORM复习
    无拘无束的爱情
    使用代理导致IE host被修改问题的解决方案
  • 原文地址:https://www.cnblogs.com/westsoft/p/5962281.html
Copyright © 2011-2022 走看看