Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Part of the problem that in Delphi, Objects may implement interfaces, but they are not in and of themselves interfaced objects. To understand this distinction, you have to look at the raw implementation of an interface on a Delphi object, and understand the reference counting mechanism used by COM. Another thing that has to be understood is that .NET doesn't work the same way, so what appears to be an interface in .NET for an object IS the same as the ComVisible aspect presented.</p> <pre><code>TYPE TMyObject = class(TInterfacedObject, IMyObject, IMyNewInterface) end; </code></pre> <p>Given the above, the following things can be said of this object. You created a new COM object using the Delphi COM object wizard. The Interface IMyObject is defined as the default interface, and TMyObject is the concrete class that will implement that interface. IMyNewInterface is a secondary interface defined somewhere else, that you have indicated your object implements.</p> <p>You can do the following with this object</p> <pre><code> var I1: IMyObject; I2: IMyNewInterface; T: TMyObject; begin I1:=TMyObject.Create; I2:=TMyObject.Create; T:=TMyObject.Create; end; </code></pre> <p>You can do these things because TMyObject IMPLEMENTS these interfaces. Also, since these are reference counted, you don't have to release them from memory, when the method scope ends, so does the lifetime of the object - WITH THE EXCEPTION OF THE LAST ONE Because you are using an OBJECT REFERENCE instead of an INTERFACE REFERENCE, you must free the OBJECT you created.</p> <p>Given the code you posted, if you look closely, you will actually find the same situation. In your case, your object is completely implemented in .NET, so what you are trying to use is a Delphi code Wrapper - which is an OBJECT, not an INTERFACE.<br> You notice on the wrapper, that there is no second method to pass an instance of the IUserInfo object to, and that is because this OBJECT is not implementing the INTERFACE, (your .NET object was created to do that) - what you need to do in Delphi is "select that interface"</p> <p>You would accomplish that task by doing the following:</p> <p>If you have already done a TUserMaintenance.Create(nil) call and have an instance of that object, get the default interface, then "cast" it to the appropriate implemented interface</p> <pre><code> var UMDelphiWrapper: TUserMaintenance; UIDelphiWrapper: TUserInfo; UI: IUserInfo; UM: IUserMaintenance; begin //this part creates a Delphi OBJECT reference to the Implementation class - //this is NOT Reference counted, because it doesn't implement an interface. UIDelphiWrapper:=TUserInfo.Create(nil); try //this is the part where you acquire the interface of the object that actually //implementes this interface - e.g. your .NET class //not that this is the INTERFACE reference - which WILL be reference counted UI:=UIDelphiWrapper.DefaultInterface as IUserInfo; //UI.&lt;Set some properties of your IUserInfo object&gt; try //this part creates a Delphi OBJECT reference to the Implementation class - //this is NOT Reference counted, because it doesn't implement an interface. UMDelhpiWrapper:=TUserMaintenance.Create(nil); try //this is the part where you acquire the interface of the object that actually //implementes this interface - e.g. your .NET class //not that this is the INTERFACE reference - which WILL be reference counted UM:=UMdelphiWrapper.DefaultInterface as IUserMaintenance; try //Here, you have an interface type implemented by your .NET class that you are //sending to the implementation of your management object (Also a .NET class) UM.SendUser(UI); //do whatever else you need to do with your interface and user/management .NET object(s) finally //this IS a reference counted COM object - no "free" necessary //this would naturally happen when the reference goes out of scope in the method //but for clairity sake is set to NIL to explicitly release your reference UM:=nil; end; finally //This is a delphi object that is NOT reference counted and must be released FreeAndNil(UMDelphiWrapper); end; finally //this IS a reference counted COM object - no "free" necessary //this would naturally happen when the reference goes out of scope in the method //but for clairity sake is set to NIL to explicitly release your reference UI:=nil; end; Finally //This is a delphi object that is NOT reference counted and must be released FreeAndNIl(UIDelphiWrapper); end; </code></pre> <p>In addition to actually using the Delphi provided wrappers you could instead directly create references to your .NET objects as long as you know the correct information.</p> <pre><code>var UI: IUserInfo; UM: IUserManager; begin UI:=CreateOleObject('YourAssembly.YourImplementationClass') as IUserInfo; UI.SomeProperty:=SomeValue; UM:=CreateOleObject('YourAssembly.YourImplementationClass') as IUserManger; UM.SomeMetohd(UI); end; </code></pre> <p>This code is much cleaner - however, you must still have the accurate definition of IUserInfo and IUserMaintenance, as well as know the class friendly name of your objects as they have been registered with COM.</p> <p>You could do this yourself by typing the code out - this is what the type import function should have done for you when you imported the COM exposed DLL from your assembly. I didn't see the actual implementation in the code you provided, but you should still find this information in your header file. -- If you don't, then you didn't import the correct assembly, or the Delphi 7 import didn't function correctly - or it needs to be refreshed (e.g. you added new methods to your .NET implementation, but didn't re-register (with COM) and re-import the new assembly type info). </p> <pre><code>type IUserInfo = interface ['22222222-2222-2222-2222-AAAAAAAAAAAA'] //define your methods end; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload