zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    运算符重载
    LPCRITICAL_SECTION 函数
    让你弄明白高斯核是怎样进行滤波工作的
    sln文件
    内联函数
    C++对文本的操作
    数组形参
    内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区[C++][内存管理]
    怎样对付win7黑屏
    C++ 模板
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/6554648.html
Copyright © 2011-2022 走看看