AV when accessing UserSession

delphi package - automated exception handling
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

Post 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}

madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Did you try "exceptIntf.RelatedObject", as I suggested in my previous comment?
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

I could not access AApplication or UserSession through "exceptIntf.RelatedObject"
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

Post by madshi »

Try this:

Code: Select all

if Assigned(exceptIntf.RelatedObject) and (exceptIntf.RelatedObject is TIWApplication) then
  with TIWApplication(exceptIntf.RelatedObject) do
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

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

Re: AV when accessing UserSession

Post by madshi »

So all problems solved?
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

It looks like it. Thanks
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post 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.
Post Reply