安全数据SAFEARRAY 在delphi中如何使用?(100分)

  • 主题发起人 主题发起人 浮云一号
  • 开始时间 开始时间

浮云一号

Unregistered / Unconfirmed
GUEST, unregistred user!
安全数据SAFEARRAY 在delphi中如何使用?
 
这段程序带入的安全数据参数有问题:
//定义
type
TRecord_Integer=Array of integer;
//新增加的
TRecord_String=Array of string;
//新增加的


//OFW1消费服务器 采集数据 --此段程序执行时Get_Record_ALL返回值不为0 (为-99)
Function TfrmKQFGDownLoad.pri_FunDataDownLoad1(parDbgrid:TDbgridEh):boolean;
var
I:integer;

Record_ZhiZheng,Record_Num:integer;
TX_End:integer;
//通讯结果 pau
Record_SKY:PSafeArray;//array[0..17] of integer;//收款员代号
Record_Date:PSafeArray;//array[0..17] of String;//记录日期
Record_Card:PSafeArray;//array[0..17] of String;
//卡
Record_Type:PSafeArray;//array[0..17] of integer;//类型
Record_XF_Now:PSafeArray;//array[0..17] of integer;// '金额
Record_Mach_Liu:PSafeArray;//array[0..17] of integer;//机流水
Record_Mach_Num:PSafeArray;//array[0..17] of integer;//消费机号
vrEl:integer;
pt1,pt2,pt3,pt4,pt5,pt6,pt7: Pointer;
begin

if EdFileName.Text='' then

begin

Pri_proAppendLog(Caption+': 配置文件错误,下载数据失败!',Dbgrid2);
exit;
end;


Record_ZhiZheng:=0;// 开始指针为重复采集记录的指针数,一般从 0 开始,
//采集完成后intStartRecordOrder 开始指针应加上刚才所成功采集的记录数
Pri_proAppendLog(Caption+': 正在下载数据,请稍候...',Dbgrid2);
try
vrEl:=17;
// SAFEARRAYBOUND(Bound);
Record_SKY:=SafeArrayCreate(VT_VARIANT,1,vrEl);
Record_Date:=SafeArrayCreate(VT_VARIANT,1,vrEl);
Record_Card:=SafeArrayCreate(VT_VARIANT,1,vrEl);
Record_XF_Now:=SafeArrayCreate(VT_VARIANT,1,vrEl);
Record_Mach_Liu:=SafeArrayCreate(VT_VARIANT,1,vrEl);
Record_Mach_Num:=SafeArrayCreate(VT_VARIANT,1,vrEl);

while truedo

begin

TX_End:=OFW1_OCX1.Get_Record_ALL(pri_FunGetID(DBCBoxStyle.ItemIndex)
,EdtNetPort.Text,1000, EdtPassword.Text
,Record_ZhiZheng,Record_Num,Record_SKY,Record_Date,Record_Card
,Record_Type,Record_XF_Now,Record_Mach_Liu,Record_Mach_Num);

Result:=(TX_End=0);
if not Result then
break;
//0:采集成功
If Record_Num = 0 then
break;

SafeArrayAccessData(Record_SKY,pt1);
SafeArrayAccessData(Record_Date,pt2);
SafeArrayAccessData(Record_Card,pt3);
SafeArrayAccessData(Record_Type,pt4);
SafeArrayAccessData(Record_XF_Now,pt5);
SafeArrayAccessData(Record_Mach_Liu,pt6);
SafeArrayAccessData(Record_Mach_Num,pt7);

with parDbgrid.DataSource.dataSetdo

For I:=1 To Record_Numdo

begin

Append;

FieldByName('F_ZhiZheng').AsInteger:=Record_ZhiZheng;
FieldByName('F_Num').AsInteger:=Record_Num;
FieldByName('F_SKY').AsInteger:=TRecord_Integer(pt1);
FieldByName('f_date').AsString:=TRecord_String(pt2);
FieldByName('F_CardID').AsString:=TRecord_String(pt3);
FieldByName('F_Type').AsInteger:=TRecord_Integer(pt1);
FieldByName('F_XFJe').AsCurrency:=TRecord_Integer(pt1);
FieldByName('F_MachLiu').AsInteger:=TRecord_Integer(pt1);
FieldByName('f_MachNum').AsInteger:=TRecord_Integer(pt1);
Post;
end;


SafeArrayUnAccessData(Record_SKY);
SafeArrayUnAccessData(Record_Date);
SafeArrayUnAccessData(Record_Card);
SafeArrayUnAccessData(Record_Type);
SafeArrayUnAccessData(Record_XF_Now);
SafeArrayUnAccessData(Record_Mach_Liu);
SafeArrayUnAccessData(Record_Mach_Num);

Record_ZhiZheng:=Record_ZhiZheng+Record_Num;
end;

finally
SafeArrayDestroy(Record_SKY);
SafeArrayDestroy(Record_Date);
SafeArrayDestroy(Record_Card);
SafeArrayDestroy(Record_Type);
SafeArrayDestroy(Record_XF_Now);
SafeArrayDestroy(Record_Mach_Liu);
SafeArrayDestroy(Record_Mach_Num);
end;


if not Result then

Pri_proAppendLog(Caption+': 下载数据失败! '+IntToStr(Record_Num),Dbgrid2)
else

begin

if not DirectoryExists(MainForm.pub_VarMyCurrentDir+'/'+EdBackupDir.Text) then

CreateDir(MainForm.pub_VarMyCurrentDir+'/'+EdBackupDir.Text);

CopyFile(pchar(MainForm.pub_VarMyCurrentDir+'/'+EdFileName.Text)
,pchar(MainForm.pub_VarMyCurrentDir+'/'+EdBackupDir.Text+'/'
+EdFileName.Text+FormatDateTime('yyyymmddhhsszzz',now)),False);

SaveDBGridEhToExportFile(TDBGridEhExportAsText,parDbgrid
,MainForm.pub_VarMyCurrentDir+'/'+EdFileName.Text,False);

Pri_proAppendLog(Caption+': 下载数据完成! '+IntToStr(Record_ZhiZheng),Dbgrid2);
end;

end;
 
后退
顶部