Re: TXMLDocument and TTreeView
- From: "Chris.Cheney" <Chris.CheneyXXNOSPAMXX@xxxxxxxxx>
- Date: Tue, 31 Jul 2007 10:14:44 GMT
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.
.
- References:
- TXMLDocument and TTreeView
- From: Cafetorium
- Re: TXMLDocument and TTreeView
- From: Chris.Cheney
- Re: TXMLDocument and TTreeView
- From: Cafetorium
- Re: TXMLDocument and TTreeView
- From: Cafetorium
- Re: TXMLDocument and TTreeView
- From: Chris.Cheney
- Re: TXMLDocument and TTreeView
- From: Cafetorium
- Re: TXMLDocument and TTreeView
- From: Maarten Wiltink
- Re: TXMLDocument and TTreeView
- From: Cafetorium
- TXMLDocument and TTreeView
- Prev by Date: Re: who is able to develop N-level application of delphi
- Previous by thread: Re: TXMLDocument and TTreeView
- Next by thread: Re: TXMLDocument and TTreeView
- Index(es):
Relevant Pages
|