variant保存tdatetime, 为什么读回的时候不正确? ( 积分: 200 )

  • 主题发起人 主题发起人 hsgrass
  • 开始时间 开始时间
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;
 
解决了
varByte -->varInteger
tks
 
哈哈,自己搞定了
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
722
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
883
import
I
后退
顶部