2Pascal-新时代的Pascal

标题: 我要使用DataSnap从服务器内存读出流数据,不是数据库 [打印本页]

作者: 螃蟹    时间: 2015-5-19 11:23
标题: 我要使用DataSnap从服务器内存读出流数据,不是数据库
测试DataSnap可以调用服务方法写入一个stream到服务器的内存,但是测试读出服务器的内存到一个Stream报错,方式是付给服务器方法stream指针

作者: wang_80919    时间: 2015-5-19 12:56
无代码无真相。
这里不是群,所以喜欢代码。
作者: 螃蟹    时间: 2015-5-19 14:36
服务端函数
unsigned char xxx[20480]={11,22,33,44,55},yyy[10]={0};
int  TServerMethods1::getArraypm(TMemoryStream *sm)
{
        sm->Position=0;
        sm->WriteBuffer(xxx,20480);
        sm->Position=0;
        return 1;
}
客户端函数
unsigned char xxx[]={5,4,3,2,1,0},yyy[20480]={0};
void __fastcall TForm3::Button1Click(TObject *Sender)
{
        TMemoryStream *sm=new TMemoryStream;
        //unsigned char *p=new char[100];
        ClientModule1->ServerMethods1Client->getArraypm(sm);
        sm->Position=0;
        sm->ReadBuffer(yyy,sm->Size);
        sm->Position=0;
        AnsiString ss;
        ss=ss.sprintf("%d,%d,%d,%d,%d",yyy[0],yyy[1],yyy[2],yyy[3],yyy[4]);
        Edit1->Text=ss;
}
服务端执行到sm->WriteBuffer(xxx,20480);的时候报stream写入错误
如果把这个服务端函数作为本地调用是没问题的




作者: wang_80919    时间: 2015-5-19 15:52
sorry 不懂 c++是不是 char 不行。你换 byte 试试。

另外,就算是 delphi ,我也经常搞不懂 WriteBuffe Write 的区别。
而且,他们的参数和数组和指针,如何配套,我也是糊里糊涂。

所以,我经常是换着写。
例如
var
  a:array of int;

writebuffer(a, 10);
不行就是
writebuffer(a[0], 10);

反正就是换来换去,说不定就正常了。


作者: 螃蟹    时间: 2015-5-20 07:25
这是代理生成的代码
int __fastcall TServerMethods1Client::getArraypm(TMemoryStream* sm)
{
  if (FgetArraypmCommand == NULL)
  {
    FgetArraypmCommand = FDBXConnection->CreateCommand();
        FgetArraypmCommand->CommandType = TDBXCommandTypes_DSServerMethod;
    FgetArraypmCommand->Text = "TServerMethods1.getArraypm";
        FgetArraypmCommand->Prepare();
  }
  FgetArraypmCommand->Parameters->Parameter[0]->Value->SetStream(sm, FInstanceOwner);
  FgetArraypmCommand->ExecuteUpdate();
  int result = FgetArraypmCommand->Parameters->Parameter[1]->Value->GetInt32();
  return result;
试了,不让写入,可能是因为这个SetStream(sm, FInstanceOwner);函数,GetStream(bool)函数不能带sm参数,DBXReader不会用,改成回调函数读取了




欢迎光临 2Pascal-新时代的Pascal (http://www.2pascal.com/) Powered by Discuz! X3