Page 4 of 5

Re: AV when accessing UserSession

Posted: Tue Apr 24, 2018 6:40 am
by ZSL
FYI when I switch off MADShi, I get all the information I need when “procedure TIWServerController.IWServerControllerBaseException(AApplication: TIWApplication; AException: Exception; var Handled: Boolean);” is called.

Is there any way I can hook this into the MADShi “AddCommandLineHeaderInfo” procedure?

Re: AV when accessing UserSession

Posted: Tue Apr 24, 2018 8:21 am
by madshi
How do you get all the information you need? By using the "function UserSession: TIWUserSession" function you posted earlier? Or by using the "TIWServerController.IWServerControllerBaseException()" parameters?

And when the handler is called which madIWSupport.pas registers through "TIWServerControllerBase.RegisterExceptionCallback()", you don't get the same information?

Re: AV when accessing UserSession

Posted: Wed Apr 25, 2018 1:18 am
by ZSL
madshi wrote:How do you get all the information you need? By using the "function UserSession: TIWUserSession" function you posted earlier? Or by using the "TIWServerController.IWServerControllerBaseException()" parameters?
... by using TIWServerController.IWServerControllerBaseException(AApplication: TIWApplication; AException: Exception; var Handled: Boolean) of which the AApplication is the reference to the logged in user's UserSession.
madshi wrote:And when the handler is called which madIWSupport.pas registers through "TIWServerControllerBase.RegisterExceptionCallback()", you don't get the same information?
"TIWServerController.IWServerControllerBaseException()" is only called when my app is compiled without MADshi. In any event, I do not have "TIWServerControllerBase.RegisterExceptionCallback()" in my code and did not find any reference to it

Re: AV when accessing UserSession

Posted: Wed Apr 25, 2018 6:45 am
by madshi
Are you using the madIWSupport.pas/dfm files from my attachment zip to this thread a couple of posts ago? It has an "{$define useIWExceptionCallback}". If that define is set, it should use "TIWServerControllerBase.RegisterExceptionCallback()" to officially register an exception callback. Otherwise, it uses my old hook solution.

In both cases, you should get access to AApplication though "exceptIntf.RelatedObject".

Re: AV when accessing UserSession

Posted: Thu Apr 26, 2018 2:02 am
by ZSL
Sorry! I was confusing myself... :oops:

I did not have madIWSupport from the earlier post built into that last test- I now d.

AApplication is being assigned but with the code below, line " exceptIntf.BugReportHeader['User #'] := UserSession.gv_UID;" generates an AV. When I evaluate UserSession.gv_UID before the AV is generated, it returns a null string - by that I mean empty string.

Code: Select all

procedure TIWUserSession.IWUserSessionBaseCreate(Sender: TObject);
begin
  gv_UID := 'User';
  gv_SID := 'Site';

end;

{$IFDEF madExcept}

procedure AddCommandLineHeaderInfo(const exceptIntf: IMEException; var handled: boolean);
begin

  exceptIntf.BugReportHeader['Product'] := 'Test';
  exceptIntf.BugReportHeader['User #'] := UserSession.gv_UID;
  exceptIntf.BugReportHeader['Site ID'] := UserSession.gv_SID;

end;

initialization

RegisterExceptionHandler(AddCommandLineHeaderInfo, stDontSync);

{$ENDIF}


Re: AV when accessing UserSession

Posted: Thu Apr 26, 2018 8:21 am
by madshi
Did you try "exceptIntf.RelatedObject", as I suggested in my previous comment?

Re: AV when accessing UserSession

Posted: Thu Apr 26, 2018 10:31 pm
by ZSL
I could not access AApplication or UserSession through "exceptIntf.RelatedObject"

Re: AV when accessing UserSession

Posted: Fri Apr 27, 2018 6:36 am
by madshi
What happened when you tried? Was RelatedObject "nil"? Or did you get a crash? How exactly did your code using RelatedObject look like?

Re: AV when accessing UserSession

Posted: Fri Apr 27, 2018 10:36 am
by ZSL
I may not be calling the RelatedObject correctly to expose AApplication but I could not find any reference to it in RelatedObject so I could not build the app and when I put a break point at exceptIntf.BugReportHeader['Product'] := 'Test'; i could not find any reference to AApplication or a TIWApplication

Re: AV when accessing UserSession

Posted: Fri Apr 27, 2018 10:38 am
by madshi
Try this:

Code: Select all

if Assigned(exceptIntf.RelatedObject) and (exceptIntf.RelatedObject is TIWApplication) then
  with TIWApplication(exceptIntf.RelatedObject) do

Re: AV when accessing UserSession

Posted: Sat Apr 28, 2018 2:12 am
by ZSL
Your suggestion did not provide access to UserSession but it gave me an idea.

I have only tested this with a single session but it should work with multiple sessions. I may need to Lock/Unlock the LSessions list in a critical section - more investigation needed by me.

That said, I have attached a 7Z of the working test project.

Critiques, ripping apart, improvements, suggestion are all welcome.

Thank you for your extreme persistence and extensive help.
iwprj1.7z
test project
(4.67 KiB) Downloaded 349 times

Re: AV when accessing UserSession

Posted: Sat Apr 28, 2018 2:29 am
by ZSL
... went to make a coffee and it dawned on me that I missed your important point in your last post about

Code: Select all

if Assigned(exceptIntf.RelatedObject) and (exceptIntf.RelatedObject is TIWApplication) then
  with TIWApplication(exceptIntf.RelatedObject) do
Please see the revised project code attached.
iwprj1.7z
Revised test project
(4.71 KiB) Downloaded 353 times
Again, thank you.

... now I will make that coffee.

Re: AV when accessing UserSession

Posted: Sat Apr 28, 2018 7:09 am
by madshi
So all problems solved?

Re: AV when accessing UserSession

Posted: Sat Apr 28, 2018 8:52 am
by ZSL
It looks like it. Thanks

Re: AV when accessing UserSession

Posted: Sat Apr 28, 2018 8:54 am
by madshi
Good to hear. So which of the 2 madIWSupport variants are you using now? The hook variant, or the official callback variant? With the test project, they both seem to do the job. However, the official callback variant seems to show an extra message box, for some reason. I've asked the IW guys about that, but they didn't reply.