Re: Interface Question



Hans-Peter Diettrich wrote:
Rob Kennedy wrote:

http://www.cs.wisc.edu/~rkennedy/interface-object

A fine article :-)

I only disagree with the last paragraph(s), about how to retrieve object references. In the case of a Delphi class, the offset of the interface pointer is stored in the interface description, no need to look into the stubs (hint: the compiler obtains the offset just from that place).

How can it be stored in the interface description? Consider the record I use to describe TInterfacedObject:

type
TInterfacedObjectLayout = record
VMT: Pointer;
FRefCount: Integer;
FIUnknown: PIUnknownMT;
end;

In that class, the offset is 8, corresponding to SizeOf(VMT) + Sizeof(FRefCount). Now consider the layout of a class that implements IUnknown without reference counting:

type
TInterfacedObjectNoRefLayout = record
VMT: Pointer;
FIUnknown: PIUnknownMT;
end;

The offset in this case is only 4. The classes implement the same interface in both cases, but the offset is different. The IUnknown definition doesn't say anything about 4 or 8.

Looking into the stub code is a bit safer, because that code may be less version dependent, than the info in the classtype structure.

But there is no class type yet. All we have is an interface reference, and we're trying to get to the object. We don't know what class we'll get until after we get it.

--
Rob
.



Relevant Pages

  • Re: Tool Offset Delta
    ... We are using a Master Plane tool setting scheme. ... indicator will work), and zero the indicator. ... "incremental" Z offset to zero. ... and reset the Z reference position. ...
    (alt.machines.cnc)
  • RE: Lookup Data in two seperate Spreadsheets
    ... the Offset function says it only returns a reference not a value. ... 'Cell Formula using the OFFSET worksheet formula with multiple criteria to ... 'Returns a reference to a range that is a specified number of rows and columns ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Nesting Address function in Offset without Quotes???
    ... The INDIRECT function will convert your text string "A1" into a cell ... is a cell reference. ... Address does the trick except that the offset function ... quotes). ...
    (microsoft.public.excel.worksheet.functions)
  • Re: macro row movement
    ... But be careful when you set an offset that you have room to reference that ... Using the down arrow key places a cell reference and this won't work ...
    (microsoft.public.excel.misc)
  • Re: problem with combining functions
    ... Biff wrote: ... actually the entire array? ... The reference is not the entire range. ... MATCH,E4:E18,0)-1 tells it how many rows to offset E4 ...
    (microsoft.public.excel)