I have a dashboard form that is created when the user logs in, but if they click on another menu item before it finishes loading (the dashboard form is destroyed) I get an exception raised as it attempts to update controls that no longer exist.
Before I start creating my own solution I just wondered if anyone else has solved this already.
Example code
procedure TDashboard.LoadThingsToDo;
var
lRetval: TXDataClientResponse;
lResult: JS.TJSObject;
lToDoList: JS.TJSArray;
begin
ThingsToDo.BeginUpdate; //ThingsToDo is a TWebResponsiveGrid
try
ThingsToDo.Items.Clear;
lRetval := await(TXDataClientResponse, MainData.WebClient.RawInvokeAsync(ITUTILSSVC_GET_THINGS_TODO, []));
lResult := TJSObject(lRetval.Result);
lToDoList := JS.toArray(lResult['value']);
if (lToDoList <> nil) and (lToDoList.Length > 0) then
begin
ThingsToDo.LoadFromJSON(lResult, 'value');
ThingsToDo.Visible := True;
end
else
ThingsToDo.Visible := False;
finally
ThingsToDo.EndUpdate;
end;
end;