Re: TXMLDocument and TTreeView



If you have annotations that are pointers, it _should_ be possible to
get it working with casting interface references back and forth - but
it's not something I would trust myself for, not without extensive
debugging, retries, and altogether too much mucking around in the
disassembly view.

"should" being the operative word. I'm sure it's all possible, but I
don't see how to do it, which is why I posted on here.

Here is a short tested and working demo of how to do this with an actual
pointer (rather than a Pointer property that has a setter method as does
TTreeNode.Data):

unit Unit1;

interface

uses
Forms, Classes;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
Dialogs, // for ShowMessage
ComObj; // for CreateOleObject

// demonstrate the interface - late binding to get the Name property
procedure ShowName(Intf: IInterface);
var
V: Variant;
begin
V := Intf as IDispatch; // QI for IDispatch needed for late binding
ShowMessage(V.Name); // use late binding as no TLB to hand
end;

// demonstrate storing and retrieving an interface in a pointer
procedure TForm1.FormCreate(Sender: TObject);
var
ThePointer: Pointer;
Intf: IInterface;
begin
// Ensure ThePointer starts off nilled
// because _Release will be called on the first interface assignment
ThePointer := nil;
// Assign an interface to a pointer - casting the destination
// to IInterface ensures that _Release and _AddRef are called
IInterface(ThePointer) := CreateOleObject
('InternetExplorer.Application');
// Retrieve the interface from ThePointer
Intf := IInterface(ThePointer);
// demonstrate that the interface has been retrieved
ShowName(Intf);
// When ThePointer goes out of scope _Release will not be called
// so we must code some explicit action to do it -
// i.e. assign nil casting the destination pointer
IInterface(ThePointer) := nil;
// finish!
Application.Terminate;
end;

end.
.



Relevant Pages

  • Re: Aironet 1200 - Axis Camera
    ... packet retries 128 drop-packet ... This will keep them from dropping the connection when they have a hard ... time getting a packet through the channel. ... ~ Warning Interface Dot11Radio0, ...
    (comp.dcom.sys.cisco)
  • Aironet 1200 - Axis Camera
    ... access point setup as an Access Point. ... Warning Packet to client 001b.536c.65f0 reached max retries, ... Warning Interface Dot11Radio0, ...
    (comp.dcom.sys.cisco)
  • Re: CComPtr strange behaviour
    ... IUnknown that is an upcast from the interface identified by riid (so ... I didn't think I was doing _any_ casting. ... plain-old casting of COM interface pointer was allowed and when not so I ...
    (microsoft.public.vc.atl)
  • Re: C# DLL mittels COM-Interop aus C aufrufen
    ... Have u tried the IDispatch interface, which is used for those language ... which doesnot have capability of maintaining VTables. ... The __cplusplus symbol is defined automatically when you're compiling C ... appropriate function pointer type. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Pointers in derived types, help needed
    ... subroutine/function must have an explicit interface. ... C is not a pointer. ... then probably the best thing to do is use allocatables. ...
    (comp.lang.fortran)