Code:
#define offsetof(struct_type, member) \
(size_t) &(((struct_type *)0)->member)
This would presumably it look something like this in Delphi.
Delphi-Quellcode:
function OffsetOf(StructType: Type; Member: string): Integer;
type P = ^StructType;
begin
//Result := Integer(@P(nil)^.[Member]) - Integer(@P(nil)^);
//Result := Integer(@P(nil)^.[Member]) - Integer(P(nil));
//Result := Integer(@P(nil)^.[Member]) - 0;
Result := Integer(@P(nil)^.[Member]);
end;
My code would look something like this.
Delphi-Quellcode:
function OffsetOf(StructType: Type; Member: string): Integer;
var X: StructType;
begin
Result := Integer(@X.[Member]) - Integer(@X);
end;
But Delphi does not support macros.
Zitat von
nanix:
Code:
length = OffsetOf(member, CharData) + sizeof(member->CharData);
length := Integer(@PMember(nil).CharData) + SizeOf(TMember.CharData);