"인수의 형식이 잘못되었거나 허용 범위를 벗어 났거나 서로 충돌했습니다.". 다음 코드를 실행하려고하면받는 런타임 오류 메시지입니다. 클래스 (clsReceipt)를 사용하여 영수증을 문자열 형식으로 공식화하므로 제품을 구매하기 전에 사용자가 볼 수있는 풍부한 편집 내용 (정렬 개요)을 출력 할 수 있습니다. 나는 어떤 오류도 찾을 수 없으므로 도움이 필요하다. 나는 고등학생이며 약간의 지식이 있음을 명심하십시오. Windows에서 Delphi XE3을 사용하고 있습니다. 누구든지이 문제를 해결 나를 도와 수 있다면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.
하는 것이 좋을 것 : 아래
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 함수에 대한 코드입니다 : 아래
는 btnPurchase 코드입니다 .
오류가 발생한 위치를 알려 주시면보다 쉽게 도움을 드릴 수 있습니다. 또한 컴파일러 힌트 및 경고를 활성화합니다. 당신이 처리해야 할 몇 가지가 있습니다. –
컴파일 할 때 아무런 오류나 경고가 표시되지 않기 때문에 가능하면 할 수 있습니다. 나는 단순히 프로그램을 실행하는 동안 위의 굵게 표시된 메시지를받습니다. ToString 코드에서 for-loop에 도달 할 때 가장 자주 발생하는 ToString 함수가 Richedit에 입력되면 나타납니다. 상황을 명확히하는 데 도움이되는 희망 – user3501568
정확히 무슨 일이 일어나는지 기술하십시오. IDE가 코드 줄을 찾아 내지 못하는 경우 매우 놀랍습니다. 디버거를 단계별로 실행하십시오. –