zoukankan      html  css  js  c++  java
  • datasnap传输流/文件问题

    我在datasnap服务器里面定义了方法:

    procedure UpdateDoc(ItemID : integer; doc : TStream);

    客户端

    AServerMethods_PublicClient := TServerMethods_PublicClient.Create(DM_Client.SQLConnection1.DBXConnection);
      ItemText := TMemoryStream.Create;
      try
        ItemText.LoadFromFile('E:\private\ksxt\Source\Client\Win32\Debug\blank.rtf');
        ItemText.Position := 0;
        ShowMessage('ItemText.Size := ' + IntToStr(ItemText.Size));
    
        AServerMethods_PublicClient.UpdateDoc(6, ItemText);
      finally
        ItemText.Free;
        AServerMethods_PublicClient.Free;
      end;

    但是服务器接收到的doc的size始终为-1,无法得到流。

    后使用TJSONArray进行转换,可以实现。
    服务器这样写

    procedure TServerMethods_Public.UpLoadFile(ADoc: TJSONArray);
    var
      ADBXJSONTools : TDBXJSONTools;
      AData : TMemoryStream;
    begin
      AData := TMemoryStream.Create;
      try
        AData := ADBXJSONTools.JSONToStream(ADoc) as TMemoryStream;
        ShowMessage(IntToStr(AData.Size));
        AData.SaveToFile('123.rtf');
      finally
        Adata.Free;
      end;
    end;

    客户端这样写

    ItemText.LoadFromFile('E:\private\ksxt\Source\Client\Win32\Debug\blank.rtf');
        ItemText.Position := 0;
        ShowMessage('ItemText.Size := ' + IntToStr(ItemText.Size));
        ADoc := ADBXJSONTools.StreamToJSON(ItemText, 0, ItemText.Size);
        AServerMethods_PublicClient.UpLoadFile(ADoc);



  • 相关阅读:
    leetcode_697. 数组的度
    645. 错误的集合
    leetcode_448. 找到所有数组中消失的数字
    leetcode_628. 三个数的最大乘积
    leetcode_414. 第三大的数
    leetcode_495. 提莫攻击
    leetcode_485. 最大连续1的个数
    在 Mac、Linux、Windows 下Go交叉编译
    Goland基本操作
    etcd搭建及基本使用
  • 原文地址:https://www.cnblogs.com/codingnote/p/2438673.html
Copyright © 2011-2022 走看看