Cannot read property 'cells' of undefined

Hi,


I'm attempting to access some JSON via the following components:

TWebClientConnection --> TWebClientDataset --> TWebDatasource --> TWebDBGrid

Here's my code:

  WebClientConnection1.AutoOpenDataSet := FALSE;
  WebClientConnection1.URI :=  TAppSettings.GetURL( 'user/list/all' );
  WebClientConnection1.DataNode := 'users';
  WebClientConnection1.Headers.Clear;
  authHeader := 'Bearer ' + fAccessToken;
  WebClientConnection1.Headers.Add('Authorization=' + authHeader);  // from Bruno directly
  dsUsers.FieldDefs.Clear;
  dsUsers.FieldDefs.Add('userid',ftString,38);
  dsUsers.FieldDefs.Add('username',ftString,50);
  dsUsers.FieldDefs.Add('fullname',ftString,100);
  dsUsers.FieldDefs.Add('email',ftString,255);
  dsUsers.FieldDefs.Add('roles',ftString,255);
  dsUsers.FieldDefs.Add('lastVisitDate',ftString,25);
  WebClientConnection1.Active := true;
  dsUsers.Active := TRUE;  // fails here -
  lblManageUsers.Caption := Format('Manage Users (%d)', [dsusers.RecordCount]);


At dsUsers.Active := TRUE I get the following error in the console:

WEBLib.Grids.pju:0 Uncaught TypeError: Cannot read property 'cells' of undefined
    at Object.SetColWidths (WEBLib.Grids.pju:0)
    at Object.ColCountChanged (WEBLib.Grids.pju:0)
    at Object.SetColCount (WEBLib.Grids.pju:0)
    at Object.ColumnsChanged (WEBLib.DBCtrls.pju:0)
    at Object.cb [as FOnChange] (rtl.js:211)
    at Object.Changed$1 (WEBLib.DBCtrls.pju:0)
    at Object.Update (WEBLib.DBCtrls.pju:0)
    at Object.Changed (classes.pju:0)
    at Object.InsertItem (classes.pju:0)
    at Object.SetCollection (classes.pju:0)

Thanks for your assistance.


When you set WebClientConnection.AutoOpenDataSet = false, you cannot set dsUsers.Active = true immediately after you set WebClientConnection.Active = true. 
In a web application, server connections happen ALL asynchronous. You should activate the dataset from the WebClientConnection.AfterConnect event. (or set AutoOpenDataSet = true that will internally handle this asynchronously)

Hi Bruno,


D'oh, of course.. a beginner mistake I'm afraid. 

Thanks