// // RPC,创建DOS频道... function TForm1.CreateDos(): boolean; var InParcel,OutParcel: TMBParcel; begin InParcel:=TMBParcel.create; InParcel.PutIntegerGoods('FunctionId',1); InParcel.PutStringGoods('CallerId',MBConn.WebSessionId); OutParcel:=TMBParcel.create; result:=rpc.Call('mobile/mbdos.asq',inparcel,outparcel); if result then result:=OutParcel.GetBooleanGoods('ProcessResult'); FreeAndNil(InParcel); FreeAndNil(OutParcel); end;
// // RPC,释放DOS频道... function TForm1.FreeDos(): boolean; var InParcel,OutParcel: TMBParcel; begin InParcel:=TMBParcel.create; InParcel.PutIntegerGoods('FunctionId',4); InParcel.PutStringGoods('CallerId',MBConn.WebSessionId); OutParcel:=TMBParcel.create; result:=rpc.Call('mobile/mbdos.asq',inparcel,outparcel); if result then result:=OutParcel.GetBooleanGoods('ProcessResult'); FreeAndNil(InParcel); FreeAndNil(OutParcel); end;
// // RPC,读DOS回显信息... function TForm1.ReadPrompt(): string; var InParcel,OutParcel: TMBParcel; ok: boolean; begin InParcel:=TMBParcel.create; InParcel.PutIntegerGoods('FunctionId',3); InParcel.PutStringGoods('CallerId',MBConn.WebSessionId); OutParcel:=TMBParcel.create; ok:=rpc.Call('mobile/mbdos.asq',inparcel,outparcel); if ok then ok:=OutParcel.GetBooleanGoods('ProcessResult'); if ok then result:=OutParcel.GetStringGoods('Prompt') else result:=''; FreeAndNil(InParcel); FreeAndNil(OutParcel); end;
// // RPC,发送DOS命令... function TForm1.ExecCommand(aCommand: string): boolean; var InParcel,OutParcel: TMBParcel; begin InParcel:=TMBParcel.create; InParcel.PutIntegerGoods('FunctionId',2); InParcel.PutStringGoods('CallerId',MBConn.WebSessionId); InParcel.PutStringGoods('DosCommand',aCommand); OutParcel:=TMBParcel.create; result:=rpc.Call('mobile/mbdos.asq',inparcel,outparcel); if result then result:=OutParcel.GetBooleanGoods('ProcessResult'); FreeAndNil(InParcel); FreeAndNil(OutParcel); end;
// // 定时器,用于循环读信息... procedure TForm1.Timer1Timer(Sender: TObject); var tmpstr: string; begin timer1.Enabled:=false; tmpstr:=ReadPrompt; if tmpstr<>'' then memo1.Lines.Text:=memo1.Lines.Text+tmpstr; timer1.Enabled:=true; end;
// // 自适应屏幕... procedure TForm1.FormResize(Sender: TObject); begin edit1.width:=button4.Position.X-6-edit1.Position.X; edit3.width:=button3.Position.X-6-edit3.Position.X; end;
// // 退出... procedure TForm1.Button2Click(Sender: TObject); begin if messagedlg('是否确认退出本测试程序?', TMsgDlgType.mtConfirmation, mbYesNo,0)<>mrYes then exit; mbconn.disconnect; halt; end;
// // 连接、断开... procedure TForm1.Button3Click(Sender: TObject); begin if Button3.Text='连接' then begin mbconn.Host:=trim(edit2.Text); mbconn.Port:=strtoint(edit3.Text); if mbconn.connect then begin Button3.Text:='断开'; if CreateDos then begin memo1.Lines.Clear; Timer1Timer(nil); end else memo1.Lines.Add('创建远程DOS频道失败!'); end else memo1.Lines.Add('连接应用服务器失败!'); end else begin FreeDOS; memo1.Lines.Add(''); memo1.Lines.Add('远程DOS频道关闭啦!'); timer1.Enabled:=false; mbconn.disconnect; Button3.Text:='连接'; memo1.Lines.Add('与应用服务器断开啦!'); end; end;
// // 执行一个Dos命令... procedure TForm1.Button4Click(Sender: TObject); begin ExecCommand(trim(edit1.Text)); if stricomp('CLS',pchar(trim(edit1.Text)))=0 then memo1.Lines.Clear; edit1.Text:=''; end;
// // 清屏... procedure TForm1.Button5Click(Sender: TObject); begin memo1.Lines.Clear; end;