I have a web app written in Delphi 12 using TMS Webcore components.
At logout (which happens by user action, or after idle timeout), I want to clear the memory
- for security reasons,
- in case there are undiscovered memory leaks,
- to allow the browser to download a new version if it exists.
I keep getting an exception (shown below) on restarting the application.
Question
How can I:
- Either stop it form occurring (ideal)?
- Or capture it silently and attempt another restart?
I have tried a few options, but I keep getting an exception in the constructor of the main form. This indicates that the memory from the previous session has not been cleared.
Code for Log_Out:
procedure Tfrm_Ops_Main.Log_Out (AAuto : Boolean = False);
begin
TConsole.Log (msg_Logging_Out);
if AAuto
then Stop_Warning_User_At_Tab_Close;
Free_Child_Form;
Close;
{ Allowing for Form to Close }
// THtml.Replace_Page;
THtml.Reload_After_Delay (400);
end;
I have tried the three methods
Replace_PageReload_PageReload_Page_After_Delay
THtml class code:
class procedure THtml.Replace_Page (AUrl : string = '');
var
lUrl : string;
lTime : Int64;
begin
{ Add time in ms if same URL }
if AUrl = ''
then begin
LTime := Trunc ((Now - UnixEpoch) * ToMS);
LUrl := window.location.href + '?t=' + IntToStr (LTime);
end
else LUrl := AUrl;
document.location.replace (LUrl);
end;
class procedure THtml.Reload_Page;
begin
document.location.reload (True);
end;
class procedure THtml.Reload_After_Delay (ADelayMS : Integer);
var
LTimer : TWebTimer;
begin
LTimer := TWebTimer.Create(nil);
LTimer.Interval := ADelayMS;
LTimer.Enabled := True;
LTimer.OnTimer := Do_Reload;
end;
class procedure THtml.Do_Reload (Sender : Tobject);
begin
TWebTimer (Sender).Free;
THtml.Reload_Page;
end;
The exception fragment is:
Error: Duplicate component name: "divHeading" at Object.Create$1 (https://example.com.au/ops-test/ops_1_0_2109.js:3634:23) at Object.CreateFmt (https://example.com.au/ops-test/ops_1_0_2109.js:3641:12) at c.$create (https://example.com.au/ops-test/ops_1_0_2109.js:366:19) at Object.ValidateRename (https://example.com.au/ops-test/ops_1_0_2109.js:15533:188) at Object.SetName (https://example.com.au/ops-test/ops_1_0_2109.js:15513:21) at Object.SetName (https://example.com.au/ops-test/ops_1_0_2109.js:33680:38) at Object.LoadDFMValues (https://example.com.au/ops-test/ops_1_0_2109.js:127837:25) at Object.CreateNewForm (https://example.com.au/ops-test/ops_1_0_2109.js:43375:13) at Object.DoFormLoad (https://example.com.au/ops-test/ops_1_0_2109.js:43010:12) at XMLHttpRequest.cb (https://example.com.au/ops-test/ops_1_0_2109.js:282:28)