CONTAINING_RECORD macro in C returns the base address of a structure / record type variable based on the address of a field member in the structure. This is extremely useful in cases where I can only pass a predefined record pointer to some Windows API function that calls callbacks.
For example, if I have types such as:
type
tInnerRecord = record
x, y : integer;
end;
pInnerRecord = ^tInnerRecord
tOuterRecord = record
field1 : integer;
inner : tInnerRecord;
field2 : integer;
end;
pOuterRecord = ^tOuterRecord;
I would like to do something like:
procedure SomeCallback( pIn : pInnerRecord ); stdcall;
var
Out : pOuterRecord;
begin
Out := CONTAINING_RECORD(pIn, tOuterRecord, inner);
Out.field1 := pIn.x + pIn.y;
end;
In my specific case, I want to pass my object pointer along with the ReadFileEx (Windows Async I / O) data pointer overlay so that I can access the object in a callback.
Is there some equivalent function that provides similar functionality in Delphi (2006)?