Invalid Interface reference

I use an interface to provide some functionality to another class/module. During shutdown of my
application, the original object/form is destroyed beofre the module with the interface reference.

How should I solve this problem? There may exist several TBSShapeUI objects using the TFViewMap. And
since these objects are created dynamically I have not full control about the destroy order.

cu Christian

Here are the fragments of my code:

  IBSShapeViewMap = interface
  // some methodes

  TBSShapeUI = class(TDataModule)
  strict private
    FViewMap : IBSShapeViewMap
    constructor Create(const AViewMap: IBSShapeViewMap); reintroduce;

  TFViewMap = class(TForm, IBSShapeViewMap)

constructor TBSShapeUI.Create(const AViewMap: IBSShapeViewMap);
  inherited Create(nil);
  FViewMap  := AViewMap;
8/5/2015 2:27:13 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 12

Christian wrote:

> I use an interface to provide some functionality to another
> class/module. During shutdown of my application, the original
> object/form is destroyed beofre the module with the interface
> reference.

TDataModule and TForm both derive from TComponent.  TComponent disables reference 
counting on itself when its VCLComObject property is nil.  So, if you create 
a TForm that implements an interface, the interface's reference count will 
have no effect and thus cannot be used to extend the TForm lifetime beyond 
the TDataModule's lifetime.

> How should I solve this problem?

You can either:

1. fix your destroy order so the TBSShapeUI objects are destroyed before 
the TFViewMap object.  Or at least reset their IBSShapeViewMap interface 
references to nil before the TFViewMap object is destroyed.

2. make use of the TFViewMap.FreeNotification() method so you can detect 
when it is being destroyed and update the TBSShapeUI objects accordingly 
so they don't try to access it anymore.

3. Assign an IVCLComObject interface to the TFViewMap.VCLComObject property 
to re-enable its reference counting.  You can either:

  a. create your own class that implements IVCLComObject, have it free the 
TFViewMap object in its destructor, and then you can create and assign an 
object of that class to the TFViewMap.VCLComObject property.

  b. read the TFViewMap.ComObject property, letting its getter method create 
its own IVCLComObject object internally for itself.  You can add the System.Win.VCLCom 
unit to your uses clause to use the VCL's default creation factory, or you 
can assign your own function to the System.Classes.CreateVCLComObjectProc 
callback.  It takes a TComponent as input and returns an IVCLComObject interface 
as output.

In the case of #3, the TFViewMap might still get freed first, if it is TApplication 
that is freeing it while TBSShapeUI objects are still alive.  Which goes 
back to #1.  When you have objects that depend on a particular destruction 
order,  you need to be more active about how the objects are getting destroyed, 
you cannot always rely on implicit destructions doing the right thing, at 
least when TComponent is involved anyway.

Remy Lebeau (TeamB)
8/5/2015 6:19:37 PM
>TDataModule and TForm both derive from TComponent.  TComponent disables reference 
>counting on itself when its VCLComObject property is nil.  So, if you create 
>a TForm that implements an interface, the interface's reference count will 
>have no effect and thus cannot be used to extend the TForm lifetime beyond 
>the TDataModule's lifetime.

Yes I'm aware of that. We use that for some of our own classes as well.

>You can either:
Thanks for the suggestions.

I thought, if I would need only one method, I could pass a "reference to procedure" but I need about
3-4 methods from TFViewMap.

An abstract adapter class with a subclass of it in TFViewMap and then pass an instance of this class
would be a solution as well. More coding, but then I have no ref counting in TBSShapeUI and can just
free the adapter object in the Destroy method.

cu Christian
8/5/2015 8:30:12 PM

Similar Artilces:

Weak interface references in earlier versions of Delphi
Hi, I am working on component which need to be supported in earlier version of Delphi (starting from Delphi 6) and I have problem with reference counting of interfaces. Last days I am trying to learn more about this topic, and I have collected this info: - XE2 (or maybe XE3) include [weak] attribute, but I need to support very old Delphi 6. - At few places I have read that if I declare variable as pointer, RefCount will not be incremented. There are some traps with this approach (which I already discovered :( ), but it seems that this approach work when I assign value. But, as soon I...

Erros Invalid reference to object / Adding reference to object / Invalid server ID in backlink obituary is purged
--____SAPVXZPASDOFICLTZFCS____ Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable hi their, I have a customer who gets a lot of the above error messages. I'm thinking, it will be a timinge issue that the server cannot backlink = or sync the Database? Am I right? Or shell this be other problems? The Invalid Reference to Object is shown on User Object, simular to the = "Adding reference to object".=20 Their are 3 Netware Servers in the Network, and 2 of the are a 2 Node = Cluster. The eDir is and the OS is NW6.5 S...

DP Delphi-Reference, Meta-Searchengine for Delphi
Hi *.*, I have just revived an old project, a meta-searchengine for Delphi: it searches simultaneous: * delphi 2009 online-help hosted by embarcadero * msdn-library psdk (win32) * delphi-praxis codelibrary: ready-to-use code-snippets from one of germanys largest delphi-communities * delphi-praxis forums This project is still in progress and particularly help-content from delphi 2010 is (yet) missing. Content from MSDN needs to be complemented (expanded). Anyway - I think that searching the reference(s) AND realworld-examples in just a single click gi...

To Reference or not to Reference?
  My questions are numbered in bold for easier answering... I'm taking over an existing web app and have a question on references. When I right-click the web project and check the property pages, there are several dll references listed, some with a type BIN and others with a type GAC. 1) Why are some of listed in the web.config but others aren't? All the referenced dlls physically exist in the bin folder, including some third-party controls as a GAC type. I removed those GAC references, thinking they weren't needed because they physically exist in the bin fol...

What generals generally do
Reading a McChrystal thread elsewhere, I came across someone quoting a US general > I spent 33 years and four months in active military service and > during that period I spent most of my time as a high class thug for > Big Business, for Wall Street and the bankers. In short, I was a > racketeer, a gangster for capitalism. I helped make Mexico and > especially Tampico safe for American oil interests in 1914. I helped > make Haiti and Cuba a decent place for the National City Bank boys to > collect revenues in. I ...

To Reference or not to reference
I've written a Perl program that declares a hash at the top of the program "%myHask;". It has worked great until now when one sub program seams to be making its own copy of the hash. I can find no typo's or anything but there my still be one there. My question is would it be better to pass the global hash by reference to each sub program to cut down on possible typo errors or just leave it global and fix the problem I have? Don Dukelow On 3/29/07, Dukelow, Don <> wrote: > I've written a Perl program that declares a hash at the top...

Sorry if this is "out of topic"! but since some days ago I can't read the group *embarcadero.public.delphi.language.delphi.general* Does anybody know if there's something wrong with it? Or maybe is my reader? (Thunderbird) I get this messagge when I try to read the latest messages: Error! newsgroup server responded:no such article found Perhaps the article has expired <> (33145) Click here to remove all expired articles sergio wrote: > Sorry if this is "out of topic"! but since some days ago I can'...

[Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Invalid date, time or timestamp value. error
Hi everyone, have a problem with this line of code:  thisquery = "select type as tender from dlpaid where stor = '"&istor&"' and tran = '"&itran&"' and till = '"&itill&"' and date1 = '"&right(idate, 4)&"-"&right(left(idate, 5), 2)&"-"&left(idate, 2)&"'  "set ConnRsOrig =oconnPV.execute(thisquery) This error occurs sometimes but not all the time: Refund Checking fault occurredMicrosoft OLE DB Provider for ODBC Drivers error '800...

Interface Reference Error
The following piece of code is in a VB file IZipCode.VB that is in the App_Code directory.Public Interface IZIPCode ReadOnly Property ZIPCode() As String End Interface  It is referenced in a user control by the following: <%@ Implements Interface="IZIPCode" %> When I run the page that has the user control on it, I get the following error message: Parser Error Message: Could not load type 'IZIPCode'.Source Error: Line 1: <%@ Control Language="VB" ClassName="ZIPCodePart" %> Line 2: <%@ Implements Interface=&qu...

Invalid References error.
Hi , I am getting the following error messages when I run the sanity check and my bugs listed as invalid refernces are missing,Can you please suggest how to recover or view all these bugs.Please find the error message below and let me know a solution to solve this issue. Bad value "246" found in bugs_activity.bug_id Bad value "563" found in bugs_activity.bug_id Bad value "568" found in bugs_activity.bug_id Bad value "628" found in bugs_activity.bug_id Remove invalid references to non existent bugs. .... from bug_group_map.bu...

Interface reference counting...
Normally I'm used to manage correctly the interfaces and related reference counter. Today I need to bypass the native system and get an interface without increment the reference counter. Unfortunately I isn't able to understand if this code could work fine, but if you have any suggestion PLEASE help me ;) .... ... FChannels: TInterfaceList; ... .... function TBridgeManager.GetChannel(ChannelIndex: Integer): IBridgeChannel; var P: Pointer; begin if (ChannelIndex< 0) or (ChannelIndex> FChannels.Count) then begin Result := nil; Exit; ...

Interface reference counting
I rarely using Interface objects in my application development, no joke although it is weired. When I create objects implement interface, eg TMyObject1 implements interface1. TMyObject2 implements interface1. I create instances for TMyObject1 and TMyObject2. Does interface1 has count 2? Or I have totally wrong in concept? Pak Tse wrote: > Does interface1 has count 2? No. Interface references are counted, not object references. See for an explanation. -- Bill Todd (TeamB) A better article is

Invalid reference to object
While running dsrepairs to troubleshoot a different problem (see the thread on -672 in iManager), I have noticed a large amount of "Invalid reference to object" error messages. They seem to be mostly ZFD workstation objects, but are also server's sometimes. After running dsrepair multiple times, until no errors, the problem returns either on the same or new objects. Here are some copies of the error(s): ERROR: Invalid reference to object, ID: 0000896F, value is purged Attribute 3F828177, Reference Object ID: 00008904, DN: OU=LCSC.O=REMOTE.T=POST ERROR: I...

Delphi like interface
I'm making an application with a Delphi like interface. It has a main toolbar form with the menu on it. It has child editor forms. The problem I have is the menu shortcuts don't work in the child forms. This makes sense as they have the input focus, not the toolbar form. What I would like to know is how I can implement menu shortcuts from the child windows to the main toolbar? I tried catching the various WM_ messages I thought should do it in the child and passing them to the toolbar, but that didn't work. Probably I used the wrong WM_ messages. justin temby wrote: &...

Web resources about - Invalid Interface reference - embarcadero.delphi.general

Interface - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Official Google iOS app updated w/ interface tweaks, better organization of Google Now cards
... Material Design aesthetic, while the Google Now cards in the app are now organized in a much more straightforward way. The voice search interface ...

Weather Underground gets interface improvements on iOS
The popular online weather service Weather Underground has just updated its official iOS app with a number of interface enhancements, thereby ...

Disney CEO & Apple board member Bob Iger calls Apple TV best television interface ever
... Executive Bob Iger said in an interview on Monday, praising Apple for creating what he believes is the most intuitive television user interface ...

Playing around with BMW’s 7 Series gesture control user interface
... we showed you Dragon Drive , the voice-activation system that's now included in BMW's 7 Series. That's not the only advanced user interface ...

Firefox 43 adds new block list, updates Android user interface
Mozilla has rolled out Firefox 43 FINAL for Windows, Mac and Linux, with Firefox 43 for Android due to follow imminently. The desktop build ...

Samsung Shows Off New Smart Remote and Interface for Their Smart TVs
... hubs in 2016. On top of extensive smart home control by way of SmartThings , the company’s line of smart TVs will also be getting a user interface ...

IDG Contributor Network: Post-acquisition, LastPass rolls out new version with more user interface bling ...
... exists, revenue streams are sure to eventuate. The new version of LastPass, imaginatively called LastPass 4.0, has an entirely new user interface ...

Android’s design guru says iPhone interface is ‘heavy and burdensome’
The arrival of the original iPhone may have fundamentally changed Google’s plans for its Android smartphone platform, but according to Google’s ...

Sling TV Plans New Interface And Guide That Predicts What Users Want
... Sling CEO Roger Lynch says that the service won’t hike the price this year. He also said that later this quarter it will roll out a new interface, ...

Resources last updated: 1/23/2016 2:36:25 AM