Unknown error

The code below creats an error when clicking the button
ERROR Uncaught [ object object] | FMessage: : FhelpContext: :0 FJS ERROR: : null
FStack::undefined at http://localhost:8000/ProjectTest2/ProjectTest2.js [541:9]

The code
var
Form1: TForm1;

CONST
C_JustUpdate = 0;
C_CreateSortOrder = 1;
implementation
{$R *.dfm}
procedure TForm1.WebButton1Click(Sender: TObject);
begin
XDataWebDataSet1.Close;
end;

procedure TForm1.WebFormCreate(Sender: TObject);
begin
WhatsNext :=1;
XDataWebDataSet1.Load;
end;

procedure TForm1.XDataWebDataSet1AfterClose(Dataset: TDataSet);
begin
XDataWebDataSet1.Load;
end;

procedure TForm1.XDataWebDataSet1AfterOpen(Dataset: TDataSet);
begin
XDataWebDataSet1.First;
CASE WhatsNext OF
C_JustUpdate:
BEGIN
XDataWebDataSet1.Edit;
XDataWebDataSet1.FieldByName('SortOrder').AsInteger := WebSpinEdit1.Value;
XDataWebDataSet1.Post;
XDataWebDataSet1.ApplyUpdates;
XDataWebDataSet1.Close;
END;
C_CreateSortOrder:
BEGIN
WhatsNext :=-0;
END;
END;
end;
end.

First, it's a lot easier to read code if you highlight it all and then click the </> tag above.

Second, it says you have a null pointer somewhere.

You don't have a whole lot of objects defined there, so I'm going to take a wild guess that it's probably XDataWebDataSet1.

If it's not that then it's the form. What other choices do you have?

Both of them are easy to check in the browser's debugger. (Hit F12 in Chrome.)

  1. Is it intentional you call Load from the AfterClose event?
  2. Open the browser console, it has more info, including call stack of where the error happened

The problem is in a much bigger project but I made a testproject just to find out wher the problem is
As I find out earlier I must check that close is ready before calling load and that load is redy before doing somthing with the database thats the reason for the construction .
Screenshot_1

I first do this
XDataWebDataSet1.Edit;
XDataWebDataSet1.FieldByName('SortOrder').AsInteger := WebSpinEdit1.Value;
XDataWebDataSet1.Post;
XDataWebDataSet1.ApplyUpdates;
And the close seams to have success
XDataWebDataSet1.Close;
Then I come to this
procedure TForm1.XDataWebDataSet1AfterClose(Dataset: TDataSet);
begin
XDataWebDataSet1.Load; // And this is the point wher the erros comes
end;

The rtl.js is over my programing skills to understand

ApplyUpdates is an asynchronous operation. If you cal Close right after calling it, then when the actually updates are applied, the dataset is already closed.

Use the AfterApplyUpdates event for that.