delphi - Why `as` operator might throw nasty EAccessViolation instead of normal EIntfCastError? -


I have created a highly experimental and unstable IDE add-in, which causes extremely bad A / V on the IDE shutdown. (Recently breaks feature projects, Gran!) I finally narrowed it down to the specific killer:

  destructor TMyAddIn.Destroy; Get started {$ IFDEF DEBUG} {The bug is here, A / V causes IOTAMessage services (BorlandIDEServices) when it's closed. AddTitleMessage ('Bye'); {$ ENDIF} {...} {Finishing up stuff} {...} inherited; End;   

A / V exception <0> has read at 0x00000008 .

I have added more security to the problematic statement:

  If specified (BorlandIDEServices) then {passes} if supported (BorlandIDEServices, IotAMessage services) then { Failed} (BorlandIDEServices as IotAmessageServices). AddTitleMessage ('Bye');   

... and found that (1) pointer still does not work zero (2) QueryInterface (3) The desired interface no longer exists, given that everything looks normal, I hope friendly EIntfCastError . But why have I got an A / V instead?

My guess is that

  1. BorlandIDEServices is not valid but it is also not valid

  2. BorlandIDEServices is valid, but its internal IOTAMessageServices Not implemented.

    They can read for an address 0x00000008 error

    Instead of the first IotAMessageServices You can get the interface and hold it, thus it is still valid in your destructor because of the reference count, example:

      {$ IFDEF debuts} private messaging service: IotAMessageServices; {$ ENDIF} Constructor TMyAddIn.Create; Heritage begins; {...} {Initial Stuff} {...} {$ IFDEF Debuts} MMSSVC: IorAmessageServices = BorlandIDEServices; MsgSvc.AddTitleMessage ('Hello'); End of {$ ENDIF}; Destructor TMyAddIn.Destroy; Get started {$ IFDEF DEBUG} MsgSvc.AddTitleMessage ('Bye'); {$ ENDIF} {...} {Finishing up stuff} {...} inherited; End;    

Comments

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -