TSimpleMsgPack的样例代码

发布时间:2017-3-20 6:58:17编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"TSimpleMsgPack的样例代码 ",主要涉及到TSimpleMsgPack的样例代码 方面的内容,对于TSimpleMsgPack的样例代码 感兴趣的同学可以参考一下。

TSimpleMsgPack的样例代码

unit uMain;

interface

uses
SimpleMsgPack, Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPServer,
IdThreadMgr, IdThreadMgrPool;

const
cmd_querysql = 1;

type
TForm1 = class(TForm)
IdTCPServer1: TIdTCPServer;
IdThreadMgrPool1: TIdThreadMgrPool;
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
uDM;

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
msgpack: TSimpleMsgPack;
stream, stream2: TStream;
dm: TfrmDM;
begin
stream := nil;
msgpack := TSimpleMsgPack.Create;
stream2 := TMemoryStream.Create;
dm := TfrmDM.Create(nil);
try
try
AThread.Connection.ReadStream(stream);
stream.Position := 0;
msgpack.DecodeFromStream(stream);
case msgpack.ForcePathObject('cmd').AsInteger of
cmd_querysql:
msgpack.ForcePathObject('result').AsVariant := frmDM.QuerySQL(msgpack.ForcePathObject('sql').AsString);
end;
except
on E: Exception do
begin
msgpack.clear;
Exit;
end;
end;
msgpack.EncodeToStream(stream2);
stream2.Position := 0;
AThread.Connection.WriteStream(stream2);
finally
msgpack.Free;
stream2.Free;
dm.Free;
end;
end;

end.


上一篇:iOS for 和 forin 的区别 以及注意事项
下一篇:XAF实现交叉分析

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款