AV when accessing UserSession

delphi package - automated exception handling

Re: AV when accessing UserSession

Postby ZSL » Tue Apr 24, 2018 6:40 am

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?
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Tue Apr 24, 2018 8:21 am

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?
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Postby ZSL » Wed Apr 25, 2018 1:18 am

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
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Wed Apr 25, 2018 6:45 am

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".
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Postby ZSL » Thu Apr 26, 2018 2:02 am

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}

ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Thu Apr 26, 2018 8:21 am

Did you try "exceptIntf.RelatedObject", as I suggested in my previous comment?
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Postby ZSL » Thu Apr 26, 2018 10:31 pm

I could not access AApplication or UserSession through "exceptIntf.RelatedObject"
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Fri Apr 27, 2018 6:36 am

What happened when you tried? Was RelatedObject "nil"? Or did you get a crash? How exactly did your code using RelatedObject look like?
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Postby ZSL » Fri Apr 27, 2018 10:36 am

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
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Fri Apr 27, 2018 10:38 am

Try this:

Code: Select all
if Assigned(exceptIntf.RelatedObject) and (exceptIntf.RelatedObject is TIWApplication) then
  with TIWApplication(exceptIntf.RelatedObject) do
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Postby ZSL » Sat Apr 28, 2018 2:12 am

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.68 KiB) Downloaded 20 times
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby ZSL » Sat Apr 28, 2018 2:29 am

... 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.72 KiB) Downloaded 25 times


Again, thank you.

... now I will make that coffee.
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Sat Apr 28, 2018 7:09 am

So all problems solved?
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Postby ZSL » Sat Apr 28, 2018 8:52 am

It looks like it. Thanks
ZSL
 
Posts: 50
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Postby madshi » Sat Apr 28, 2018 8:54 am

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.
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm

PreviousNext

Return to madExcept

Who is online

Users browsing this forum: No registered users and 6 guests