我有以下C ++代码,但我仍然坚持如何在Delphi中执行等效的t = *(test *)&memory;
。
#include <iostream>
using namespace std;
struct test
{
char a, b, c, d;
};
int main()
{
char memory[] = {'a', 'b', 'c', 'd'};
test t{};
cout << "Before: " << t.a << t.b << t.c << t.d << endl;
t = *(test *)&memory;
cout << "After: " << t.a << t.b << t.c << t.d << endl;
return 0;
}
输出:
Before:
After: abcd
答案 0 :(得分:3)
看看这个:
type
PTest = ^Test;
Test = record
a, b, c, d: AnsiChar;
end;
const
Memory: array[0..3] of AnsiChar = ('a', 'b', 'c', 'd');
...
T := PTest(@Memory)^;
就是这样。 ...