Delphi REST在创建运行时时不更新VCL db组件

时间:2017-11-16 12:40:31

标签: rest delphi-10.2-tokyo

我有一个REST客户端,它使用适配器发送请求并使用响应更新一些VCL数据库组件,当REST VCL组件放在TDatamodule上时可以正常工作,但是如果我尝试创建相同的REST组件运行时,VCL数据库组件未显示数据。我可以看到数据实际上是返回的(我可以在FDMemtable中读取它们并将数据存储为文件)因此数据存在,但GUI组件不显示数据。但是,DBGrid会在更新后显示垂直滚动。 我使用的是Delphi XE10.2。

我对此感到困惑,我错过了一些东西。

function TRESTClientModule.UpdateHistory: Boolean;
var
 ARESTClient : TRESTClient;
 ARESTRequest: TRESTRequest;
 ARESTResponse: TRESTResponse;
 ARESTResponseDataSetAdapter: TRESTResponseDataSetAdapter;
 i : Integer;
 s : string;

begin
  Result := False;
  try
    ARESTClient := TRESTClient.Create('http://localhost:8080');
    ARESTRequest := TRESTRequest.Create(nil);
    ARESTResponse := TRESTResponse.Create(nil);
    ARESTResponseDataSetAdapter := TRESTResponseDataSetAdapter.Create(nil);
    try
      // bind to RESTClient
      ARESTRequest.Client := ARESTClient;

      //- Prepare to get data from 'alarms' end-point.
      ARESTRequest.Resource := 'alarms';
      ARESTRequest.Method := TRESTRequestMethod.rmGET;
      ARESTRequest.Response := ARESTResponse;

      // Link Response to dataset (FDMemtable + TDataSource)
      ARESTResponseDataSetAdapter.Dataset := AlarmHistory;
      ARESTResponseDataSetAdapter.ResponseJSON := ARESTResponse;
      ARESTResponseDataSetAdapter.RootElement := 'alarms';

      //- Add the parameter to the request.
      ARESTREquest.Params.Clear;
      with ARESTRequest.Params.AddItem do
      begin
        name := 'IncludeOOS';
        value := '0';
      end;

      ARESTRequest.Execute;
      s := ARESTResponse.Content; // returned content is present
      i := AlarmHistory.RecordCount; // the expected Recordcount is present

      Result := True;
    finally
      ARESTResponse.Free;
      ARESTResponseDataSetAdapter.Free;
      ARESTRequest.Free;
    end;
  except on E: Exception do

  end;
end;

0 个答案:

没有答案