【发布时间】:2014-07-26 14:28:05
【问题描述】:
“参数类型错误、超出可接受范围或相互冲突”。这是我尝试运行以下代码时收到的运行时错误消息。我正在使用一个类 clsReceipt 以字符串的形式制定收据,以便我可以在丰富的编辑中输出它,供用户在继续购买产品之前查看(各种概述)。我找不到任何错误,因此我需要帮助。请记住,我是一名高中生,知识有限。我在 Windows 上使用 Delphi XE3。
下面是btnPurchase的代码:
procedure TfrmBuy.btnPurchaseClick(Sender: TObject);
var
i, n, itemNumber, quant : integer;
found: boolean;
begin
repeat
i := strtoint(inputbox('Purchase','Enter the number of items you wish to buy or enter 0 to cancel',''));
until i>=0;
if i <> 0 then
begin
for n := 1 to i do
begin
found := false;
repeat
itemnumber := strtoint(inputbox('Item selection','Enter the Item number of purchase no. ' + inttostr(n),''));
if dm.ADOtbl.Locate('Item number',itemnumber,[]) then
found := true
else
showmessage('The item number you enteres was not found. Please try again.');
until found = true;
repeat
quant := strtoint(inputbox('Quantity selection','Please enter the quantity of the item you wish to purchase','>0'));
until quant >0;
Myreciept := TReceipt.create(itemnumber,quant,n,i);
end;
richedit1.Lines.Clear;
richedit1.Lines.Add(myreciept.tostring);
btnCheckout.Visible := true;
showmessage('Below is the reciept of your purchase. If you are satisfied, proceed to checkoutby selecting "Confirm" or restart by selecting "Reset"');
end;
repeat
i := strtoint(inputbox('Purchase','Enter the number of items you wish to buy or enter 0 to cancel',''));
until i>=0;
if i <> 0 then
begin
for n := 1 to i do
begin
found := false;
repeat
itemnumber := strtoint(inputbox('Item selection','Enter the Item number of purchase no. ' + inttostr(n),''));
if dm.ADOtbl.Locate('Item number',itemnumber,[]) then
found := true
else
showmessage('The item number you enteres was not found. Please try again.');
until found = true;
repeat
quant := strtoint(inputbox('Quantity selection','Please enter the quantity of the item you wish to purchase','>0'));
until quant >0;
Myreciept := TReceipt.create(itemnumber,quant,n,i);
end;
richedit1.Lines.Clear;
richedit1.Lines.Add(myreciept.tostring);
btnCheckout.Visible := true;
showmessage('Below is the reciept of your purchase. If you are satisfied, proceed to checkoutby selecting "Confirm" or restart by selecting "Reset"');
end;
end;
下面是类中ToString函数的代码:
function TReceipt.ToString: string;
var
k:integer;
begin
result := '';
result := 'Reciept' + #13 + '===============================================' + #13;
result := result + 'Order ID: ' + fOrderID + #13;
result := result + 'Item Name' + #9 + 'Quantity' + 'Cost' + #13;
for k := 1 to length(arrItemNo) do
begin
dm.ADOtbl.RecNo := arritemno[k];
result := result + dm.ADOtbl['Item Name'] + #9 + inttostr(arrQuantity[k]) + #9 + floattostrf((arrQuantity[k] * dm.ADOtbl['Price'] ),ffcurrency,5,2) + #13;
end;
result := result + #13 + #13 + 'Subtotal: ' + floattostrf(getsubtotal,ffcurrency,5,2) + #13;
result := result + 'VAT: ' + floattostrf(getVat,ffcurrency,5,2) + #13;
result := result + 'Grand Total: ' + floattostrf(ftotal,ffcurrency,5,2) + #13 + '===============================================';
end;
end.
如果有人能帮助我解决这个问题,那就太好了。
【问题讨论】:
-
如果您告诉我们错误所在,我们可以更轻松地为您提供帮助。并且还启用编译器提示和警告。您应该处理一些问题。
-
如果可以的话我会的,因为在编译时没有显示错误或警告。我只是在运行程序期间收到上面的粗体消息。一旦它到达被输入richedit 的ToString 函数,它就会出现,很可能是当它到达ToSTring 代码中的for 循环时。希望这有助于澄清事情
-
尝试并准确描述发生了什么。如果 ide 不能精确定位代码行,那就太令人惊讶了。在调试器中单步执行。
-
所有代码运行良好,因为它接受了所有输入,例如数量等。然后发生的一切就是粗体消息显示为错误消息,当我关闭它时什么也没有否则,代码将停止运行。我已经使用了这个步骤,没有任何问题。
-
我认为您引用的错误消息来自用于访问数据库的 Windows ADO 子系统。所以它可能是由你的代码引起的,但它不是来自它。您引用 ADOtbl 的地方看起来都不太可能导致它,所以我认为原因可能在您的代码中的其他地方。