Link to home
Start Free TrialLog in
Avatar of controlr
controlrFlag for Israel

asked on

IWForm - OnClose effect

I have something I need to do when a uses leaves the page.. (maybe the site too)
I tried the OnDestroy but it does not get triggered.
Any idea on how to implement this ?

Something like:
procedure TmainForm.OnClose( sender: TObject);
begin
  callSomeSillyLittleProc(param);
end;

TIWUserSession can NOT USED! since it requires hugh overhead (too many users)

TIA
Avatar of jimyX
jimyX

The OnDestroy gets triggered when you call release:

 
procedure TformMain.IWButtoncloseClick(Sender: TObject);
begin
  Release;
end;

procedure TformMain.IWAppFormDestroy(Sender: TObject);
begin
  callSomeSillyLittleProc(param);
end;

Open in new window



But if you close with WebApplication.Terminate then you can think of something like this (smart but not the best):
Make "callSomeSillyLittleProc(param)" a function that returns a string rather than a procedure;
pass it as a parameter to WebApplication.Terminate(callSomeSillyLittleProc(param));
Make sure the function is returning blank (Result := '');

uses SysUtils; //for inttostr

function TformMain.callSomeSillyLittleProc(i,j:integer; str:string):string;
begin
  WebApplication.showmessage(IntToStr(i+j) +' '+ str);
  Result := '';
end;

procedure TformMain.IWButtonCloseClick(Sender: TObject);
begin
  WebApplication.Terminate(callSomeSillyLittleProc(3,1,'closed, Goodbye!'));
end;

Open in new window

Avatar of controlr

ASKER

JImmy...
The user does not hit any button.. .. he simply closed the browser.. (CTRL+F4) and does not have any interaction with the page.

THerefore.. there is never a call made to release.. and thus (like i said) the destroy does not get triggered.

There should be a onTerminate events that gets triggered when browser is closed or the user goes to another URL.... but   I think its handles in teh Session timeout and there is no way to intercept it..  maybe eBob has a trick :)
ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i can use that :)
Thanks!