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.

  • 相关阅读:
    洛谷 [SDOI2015]约数个数和 解题报告
    multiset-count
    multiset-begin
    multiset-begin
    set-value_comp
    set-value_comp
    multiset-constructors
    multiset-constructors
    set-upper_bound
    set-upper_bound
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/6554648.html
Copyright © 2011-2022 走看看