DELPHI DataSnap Restful 连接方式2--使用FDConnection

1、加入“FDConnection”控件

2.设置FDConnection参数

loginprompt设为false

Protaotol 设为http

server

port

 

3、点击“Test”

 

这就表示成功连接到了Datasnap Rest 服务器

 

4、加入“FDStoredProc”控件

5、在FDStoredProc1的StoredProcName中可以找到datasnap Rest服务器端的函数

6、在窗体总调用服务器端函数

procedure TForm1.Button1Click(Sender: TObject);
var
  st: TStringStream;
begin

  try

    begin

      if FDConnection1.Connected = false then
        FDConnection1.Connected := True;

    end
  except
    on e: Exception do
    begin
      ShowMessage('FDConnection1.Connected  log发生错误' + e.message);
      Memo1.Text := e.message;
      Exit;
    end;
  end;

  try

    begin
      FDStoredProc1.ExecProc;
    end
  except
    on e: Exception do
    begin
      ShowMessage('FDStoredProc1.ExecProc;  log发生错误' + e.message);
      Exit;
    end;
  end;

  st := TStringStream.Create(FDStoredProc1.Params[0].AsBlob);

  try
    if st <> nil then
    begin
      st.Position := 0;
      FDMemTable1.LoadFromStream(st, TFDStorageFormat.sfBinary);

    end
  except
    raise;

  end;

  st.Free;

end;

 

7、如果出现以下错误提示

Protocol http can be used after an adequate instance of TDBXCommunicationLayer is registered with TDBXCommunicationLayerFactory.

在USES 中加入 Data.DbxHTTPLayer

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值