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
-
BorlandIDEServices is not valid but it is also not valid -
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
Post a Comment