为什么我取不到结构体中的值,请各位大侠帮忙啊!!!!(30)

L

longqcc

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
type TPosInvoiceItems = record ItemCode :array [0..15] of Char
ItemName :array [0..40] of Char
ItemQuantity :Single
UnitPrice :Single
ItemAmount :Single
Extra1 :array [0..20] of Char
//备用1 end
pPosInvoiceItems=^TPosInvoiceItems
TPosInvoice = record POSID :array [0..2] of Char
TransactionType :Char
TransactionNumber :array [0..10] of Char
TransactionDate :array [0..8] of Char
TransactionTime :array [0..6] of Char
CashierName :array [0..30] of Char
SiteID :array [0..3] of Char
SiteName :array [0..40] of Char
NozzleNum :array [0..4] of Char
ItemCount :Word
//商品项目数量 TotalAmount :Single
//应收金额 InvoiceAmount :Single
//实收金额 DiscountAmount :Single
//优惠金额 Extral1 :array [0..40] of Char
//备用1 Extral2 :array [0..40] of Char
//备用2 Extral3 :array [0..40] of Char
//备用3 ItemsInfo :pPosInvoiceItems
end
pPosInvoice=^TPosInvoice;function Tax_Invoice(PrtValue:pPosInvoice):Integer;var Code,S,RetStr:string
CodeLen,CodePos,CodeNum,ItemCount,I:Integer
tmpItems:pPosInvoiceItems;begin S:=PChar(@PrtValue^.POSID)
Code:=StrToHexASC(S,'HB',2)
//POS机编号 S:=LStr(PChar(@PrtValue^.TransactionType),1)
Code:=Code+StrToHexASC(S,'HB',1)
//交易类型 S:=PChar(@PrtValue^.TransactionNumber)
Code:=Code+StrToHexASC(S,'HB',10);//交易流水号 S:=PChar(@PrtValue^.TransactionDate)
Code:=Code+StrToHexASC(S,'HB',8)
//打印日期[blue] tmpItems:=PrtValue^.ItemsInfo
for I:=0 to ItemCount-1 do begin S:=PChar(@tmpItems^.ItemCode)
S:=PChar(@PrtValue^.ItemsInfo^.ItemCode)
Code:=Code+StrToHexASC(S,'HB',15)
//商品编码 S:=PChar(@PrtValue^.ItemsInfo^.ItemName)
Code:=Code+StrToHexASC(S,'HB',40)
//商品名称 Code:=Code+IntToHex(Trunc(PrtValue^.ItemsInfo^.ItemQuantity*100),8)
end;[/blue]end;为什么我取不到结构体中的值,请大家帮忙啊!就是红色部份
 
L

longqcc

Unregistered / Unconfirmed
GUEST, unregistred user!
 tmpItems:=PrtValue^.ItemsInfo
//这里这样赋值对吗? for I:=0 to ItemCount-1 do begin S:=PChar(@tmpItems^.ItemCode)
               //取不到值 S:=PChar(@PrtValue^.ItemsInfo^.ItemCode);          //取不到值 Code:=Code+StrToHexASC(S,'HB',15)
S:=PChar(@PrtValue^.ItemsInfo^.ItemName);          //取不到值 Code:=Code+StrToHexASC(S,'HB',40)
Code:=Code+IntToHex(Trunc(PrtValue^.ItemsInfo^.ItemQuantity*100),8);//取不到值 end;问题就出现在这里,取不到值?请各位大侠帮忙啊!!!!!!!!
 
P

pengdh

Unregistered / Unconfirmed
GUEST, unregistred user!
问题1、ItemCount好像初始值为0,是不是循环体进不去啊?;2、tmpItems:=PrtValue^.ItemsInfo//这样赋值可以;3、S:=PChar(@tmpItems^.ItemCode);中tmpItems已经是一个指针,为什么前面要加上@ 直接写为S:=PChar(tmpItems^.ItemCode)即可;下同。4、如3,第一行S:=PChar(@PrtValue^.POSID);中的@我也觉得多余。
 
L

longqcc

Unregistered / Unconfirmed
GUEST, unregistred user!
pengdh: 首先谢谢你的热心帮助,循环体这块不用关心。 问题是在二层结构体中,我内部结构体中取不到值。对于字符数组,前面必须加上@,如果去掉编译都通不过。
 
D

dina110

Unregistered / Unconfirmed
GUEST, unregistred user!
TPosInvoice = record POSID :array [0..2] of Char
TransactionType :Char
TransactionNumber :array [0..10] of Char
TransactionDate :array [0..8] of Char
TransactionTime :array [0..6] of Char
CashierName :array [0..30] of Char
SiteID :array [0..3] of Char
SiteName :array [0..40] of Char
NozzleNum :array [0..4] of Char
ItemCount :Word
//商品项目数量 TotalAmount :Single
//应收金额 InvoiceAmount :Single
//实收金额 DiscountAmount :Single
//优惠金额 Extral1 :array [0..40] of Char
//备用1 Extral2 :array [0..40] of Char
//备用2 Extral3 :array [0..40] of Char
//备用3 ItemsInfo :TPosInvoiceItems
end
pPosInvoice=^TPosInvoice;function Tax_Invoice(PrtValue:TPosInvoice):Integer;var Code,S,RetStr:string
CodeLen,CodePos,CodeNum,ItemCount,I:Integer
tmpItems:pPosInvoiceItems;begin S:=PrtValue.POSID)
Code:=StrToHexASC(S,'HB',2)
//POS机编号 ...[blue] tmpItems:=PrtValue.ItemsInfo
for I:=0 to ItemCount-1 do begin S:=tmpItems.ItemCode)
S:=PrtValue.ItemsInfo.ItemCode)
... end;[/blue]end;试试这个
 
L

lcd_733

Unregistered / Unconfirmed
GUEST, unregistred user!
可能是ItemsInfo没有New,所以内存里没有数据。S:=tmpItems^.ItemCode;这样赋值就可以呀。
 
顶部