H
hsgrass
Unregistered / Unconfirmed
GUEST, unregistred user!
function LoadVariantArray(PData: Pointer;
NumBytes: Integer; var VData: Variant): integer;
var
PVData: PByteArray;
begin
result := 0;
{ Create the variant array of bytes. Set the upper bound
to the size of the array, minus one, because the array
is zero-based. }
VData := VarArrayCreate([0, NumBytes - 1], varByte);
{ Lock the variant array for faster access. Then copy the
array to the variant array, and unlock the variant
array. }
PVData := VarArrayLock(Vdata);
try
{ Move the bytes at the location in memory that PData
points to into the location in memory that PVData
points to. PData points to the integer array and
PVData points to the variant array of bytes. }
Move(PData^, PVData^, NumBytes);
result := NumBytes;
finally
VarArrayUnlock(VData);
end; // try
end;
function UnloadVariantArray(
VData: Variant; PData: Pointer; NumBytes: integer): integer;
var
PVData: PByteArray;
begin
result := 0;
{ Lock the variant array, copy the data to the array, and
unlock the variant array. }
PVData := VarArrayLock(VData);
try
{ Move the data in memory that PVData points to (the
variant array data), to the location in memory that
PData points to (the integer array). }
NumBytes := VarArrayHighBound(vdata, 1);
Move(PVData^, PData^, NumBytes);
result := numbytes;
finally
VarArrayUnlock(VData);
end; // try
end;
type
ptest1 = ^ttest1;
ttest1 = record
a: string[22];
b: tdatetime;
end;
procedure TForm5.FormCreate(Sender: TObject);
var
t: ttest1;
v: variant;
begin
v := now;
t.b := v;
showmessage(datetimetostr(t.b));
t.a := 'abc';
t.b := now;
loadvariantarray(@v, sizeof(t), v);
showmessage(datetimetostr(t.b)); // 写入的时候好的
UnloadVariantArray(v, @t, sizeof(t));
showmessage(datetimetostr(t.b)); // 变了~~怎样解决?
end;
NumBytes: Integer; var VData: Variant): integer;
var
PVData: PByteArray;
begin
result := 0;
{ Create the variant array of bytes. Set the upper bound
to the size of the array, minus one, because the array
is zero-based. }
VData := VarArrayCreate([0, NumBytes - 1], varByte);
{ Lock the variant array for faster access. Then copy the
array to the variant array, and unlock the variant
array. }
PVData := VarArrayLock(Vdata);
try
{ Move the bytes at the location in memory that PData
points to into the location in memory that PVData
points to. PData points to the integer array and
PVData points to the variant array of bytes. }
Move(PData^, PVData^, NumBytes);
result := NumBytes;
finally
VarArrayUnlock(VData);
end; // try
end;
function UnloadVariantArray(
VData: Variant; PData: Pointer; NumBytes: integer): integer;
var
PVData: PByteArray;
begin
result := 0;
{ Lock the variant array, copy the data to the array, and
unlock the variant array. }
PVData := VarArrayLock(VData);
try
{ Move the data in memory that PVData points to (the
variant array data), to the location in memory that
PData points to (the integer array). }
NumBytes := VarArrayHighBound(vdata, 1);
Move(PVData^, PData^, NumBytes);
result := numbytes;
finally
VarArrayUnlock(VData);
end; // try
end;
type
ptest1 = ^ttest1;
ttest1 = record
a: string[22];
b: tdatetime;
end;
procedure TForm5.FormCreate(Sender: TObject);
var
t: ttest1;
v: variant;
begin
v := now;
t.b := v;
showmessage(datetimetostr(t.b));
t.a := 'abc';
t.b := now;
loadvariantarray(@v, sizeof(t), v);
showmessage(datetimetostr(t.b)); // 写入的时候好的
UnloadVariantArray(v, @t, sizeof(t));
showmessage(datetimetostr(t.b)); // 变了~~怎样解决?
end;