poserecord 是一个结构
如
{
name:string;
id:integer;
}
m_pDllCall->nInfoReturn = m_pDllCall->lpGetCmdResult(m_pDllCall->m_pActReturn);//取操作信息
if(m_pDllCall->nInfoReturn == nRecvSuccess)
{
int nLength = m_pDllCall->lpGetSizeOfData(m_pDllCall->m_pActReturn);
int nCount = nLength/sizeof(POSRECORD);
Label_RecvCount->Caption = IntToStr(nCount + StrToInt(Label_RecvCount->Caption));
POSRECORD *pRecordBuffer = new POSRECORD[nCount]; //这里是否是声明为 结构数组并划分了内存
POSRECORD *pBuffer = pRecordBuffer;
POSRECORD CardRecord;
m_pDllCall->lpGetData(m_pDllCall->m_pActReturn, pRecordBuffer, nLength);
for(int iLoop = 0; iLoop < nCount; iLoop ++)
{
CardRecord = *(pBuffer ++);
int nOK = m_pDllCall->WritePOSFile(nIndex, CardRecord);
if (CheckBox_Check->Checked)
{
if (nOK < 0 || nOK != 50)
{
MessageBox(Handle, "Write file error!", "Error", MB_OK);
delete []pRecordBuffer;
m_pDllCall->lpEndICDMCmd(m_pDllCall->m_pActReturn);
return;
}
}
nIndex ++;
}
delete []pRecordBuffer;
} 我转换成DELPHI后如下type
posrecordArray = array[0..0] of posrecord; //这里就算定义为[0..10]也无法以得第二个结构的资料
posrecordpoint = ^posrecordArray;
var
nRecvCount: integer;
nLength: integer;
nCount: integer;
pRecordbuffer, pBuffer:posrecordpoint; 声明为指向数组的指针
CardRecord: POSRECORD;
iloop: integer;
nOK: integer;
nTryTimes: integer; //采集数据的偿试次数
iswriteposfile: boolean;begin
result := false;
iswriteposfile := false;
fDllCall.m_nInfoReturn := nFail;
fDllCall.fSetWaitTime(Fdllcall.m_pDevice, 1500);
nRecvCount := 50;
if (fdllcall.m_pActReturn <> nil) then
begin
fdllcall.m_nInfoReturn := fdllcall.fGetCmdResult(fdllcall.m_pActReturn); //取操作信息
if (fdllcall.m_nInfoReturn = nRecvSuccess) then
begin
nLength := fdllcall.fgetsizeofdata(fdllcall.m_pActReturn);
nCount := nLength div sizeof(POSRECORD); 、//这里取得有多少个结构
try
getmem(pRecordBuffer, sizeof(POSRECORD) * nCount); //动态分配内存
pBuffer := pRecordBuffer;
fdllcall.fgetdata(fdllcall.m_pActReturn, pRecordBuffer, nLength); for iLoop := 0 to nCount - 1 do
begin
CardRecord := pbuffer^[iloop];
inc(pbuffer); {这里指针位置下移,但我跟踪过指针所向的内容
,并不正确,总是第一个记录记数据是正常,到第二个就不正常了,不懂是哪方面的问题
if iswriteposfile then
begin
nOK := WritePOSFile(fdllcall.Filehandle, nIndex, CardRecord, fmemo);
if (nOK < 0) then //or (nOK <> 50) then
begin
freemem(pRecordBuffer, sizeof(POSRECORD) * nCount);
fdllcall.fendicdmcommand(fdllcall.m_pActReturn);
fileclose(fdllcall.Filehandle);
exit;
end;
end; inc(nIndex); end;
freemem(pRecordBuffer, sizeof(POSRECORD) * nCount);
except
end;
如
{
name:string;
id:integer;
}
m_pDllCall->nInfoReturn = m_pDllCall->lpGetCmdResult(m_pDllCall->m_pActReturn);//取操作信息
if(m_pDllCall->nInfoReturn == nRecvSuccess)
{
int nLength = m_pDllCall->lpGetSizeOfData(m_pDllCall->m_pActReturn);
int nCount = nLength/sizeof(POSRECORD);
Label_RecvCount->Caption = IntToStr(nCount + StrToInt(Label_RecvCount->Caption));
POSRECORD *pRecordBuffer = new POSRECORD[nCount]; //这里是否是声明为 结构数组并划分了内存
POSRECORD *pBuffer = pRecordBuffer;
POSRECORD CardRecord;
m_pDllCall->lpGetData(m_pDllCall->m_pActReturn, pRecordBuffer, nLength);
for(int iLoop = 0; iLoop < nCount; iLoop ++)
{
CardRecord = *(pBuffer ++);
int nOK = m_pDllCall->WritePOSFile(nIndex, CardRecord);
if (CheckBox_Check->Checked)
{
if (nOK < 0 || nOK != 50)
{
MessageBox(Handle, "Write file error!", "Error", MB_OK);
delete []pRecordBuffer;
m_pDllCall->lpEndICDMCmd(m_pDllCall->m_pActReturn);
return;
}
}
nIndex ++;
}
delete []pRecordBuffer;
} 我转换成DELPHI后如下type
posrecordArray = array[0..0] of posrecord; //这里就算定义为[0..10]也无法以得第二个结构的资料
posrecordpoint = ^posrecordArray;
var
nRecvCount: integer;
nLength: integer;
nCount: integer;
pRecordbuffer, pBuffer:posrecordpoint; 声明为指向数组的指针
CardRecord: POSRECORD;
iloop: integer;
nOK: integer;
nTryTimes: integer; //采集数据的偿试次数
iswriteposfile: boolean;begin
result := false;
iswriteposfile := false;
fDllCall.m_nInfoReturn := nFail;
fDllCall.fSetWaitTime(Fdllcall.m_pDevice, 1500);
nRecvCount := 50;
if (fdllcall.m_pActReturn <> nil) then
begin
fdllcall.m_nInfoReturn := fdllcall.fGetCmdResult(fdllcall.m_pActReturn); //取操作信息
if (fdllcall.m_nInfoReturn = nRecvSuccess) then
begin
nLength := fdllcall.fgetsizeofdata(fdllcall.m_pActReturn);
nCount := nLength div sizeof(POSRECORD); 、//这里取得有多少个结构
try
getmem(pRecordBuffer, sizeof(POSRECORD) * nCount); //动态分配内存
pBuffer := pRecordBuffer;
fdllcall.fgetdata(fdllcall.m_pActReturn, pRecordBuffer, nLength); for iLoop := 0 to nCount - 1 do
begin
CardRecord := pbuffer^[iloop];
inc(pbuffer); {这里指针位置下移,但我跟踪过指针所向的内容
,并不正确,总是第一个记录记数据是正常,到第二个就不正常了,不懂是哪方面的问题
if iswriteposfile then
begin
nOK := WritePOSFile(fdllcall.Filehandle, nIndex, CardRecord, fmemo);
if (nOK < 0) then //or (nOK <> 50) then
begin
freemem(pRecordBuffer, sizeof(POSRECORD) * nCount);
fdllcall.fendicdmcommand(fdllcall.m_pActReturn);
fileclose(fdllcall.Filehandle);
exit;
end;
end; inc(nIndex); end;
freemem(pRecordBuffer, sizeof(POSRECORD) * nCount);
except
end;
解决方案 »
- delphi连postgresql成功,但不能增加或修改记录
- 将指定行上移后指针指到原上移行
- sql 分组查询的问题
- 肥水不流外人田,MOP上有MM找BF了,还《很想找个程序员男朋友》
- Delphi5的调试问题
- 小忙一个
- stringgrid装载数据, 高手请进?
- 谁试过用midas传递大量的文本数据,高分求教
- Delphi下浮点运算的问题!
- 求 cxtreelist动态创建的代码
- 在使用twebbrouser中出现'Invalid floating point operation'错误怎么解决
- procedure WMNID(var msg:TMessage); message WM_NID;编译不能通过 求助
posrecordArray = array of posrecord;
PtrArr: posrecordArray;SetLength(PtrArr, 10);
for n := 0 to 9 do
begin
GetMem(@PtrArr[n], SizeOf(poserecord));
end; // test yixia..
http://community.csdn.net/Expert/topic/3844/3844330.xml?temp=.2971613
这里得到的pRecordBuffer内容对不对呢?如果对的话,试一试这样
PPOSRECORD=^POSRECORD;
var
pRecordBuffer:pChar; getmem(pRecordBuffer, nLength); //动态分配内存 fdllcall.fgetdata(fdllcall.m_pActReturn, pRecordBuffer, nLength);
for iLoop := 0 to nCount - 1 do
begin
CardRecord := PPOSRECORD(integer(pRecordBuffer^)+iLoop*sizeof(POSRECORD))^;
第一次取得的内容是正确的,到第二条记录时就错了,
也就是说,如果是单条数据,绝对正确,可能是指针运算错误,我先按你的方法试一下