我使用 QBFC v13 和 Delphi XE6。
目标是从我的应用程序创建 Estimate 并将其参数设置到 QuickBooks 中。
我从 QBFC13 导入类型库并将其添加到我的项目中。
我的项目编译没有错误。
我从我的应用程序(片段 1,行:04)创建了 Estimate,然后我尝试为其项目设置费率。
当我调用函数 Rate.SetValue (fragment 1, line: 06) 时,我没有收到错误消息。
然后我调用 DoRequest (fragment 1, line: 07) 就可以了。
当我检查 StatusCode(片段 1,第 09 行)时,它必须为 0。但它是 3045,StatusMessage(片段 1,第 10 行):
“在'项目成本'字段中转换价格'23.00'时出错。QuickBooks错误消息:此字段包含无效字符”。
问题一:为什么会这样? (变量 'rate' 是 double 并且原型(prototype) SetValue(val: Double) 具有 double 类型)。
片段 1:
01: var
02: rate: double;
i: integer;
03: rate := 23.00;
....
04: estimateAdd := requestMsgSet.AppendEstimateAddRq();
....
05: estimateLineAdd := estimateAdd.OREstimateLineAddList.Append.EstimateLineAdd;
....
06: estimateLineAdd.ORRate.Rate.SetValue(rate);
....
07: QueryResponse := SessionManager.DoRequests(requestMsgSet);
08: i := response.StatusCode;
09: if (i <> 0) then
10: MessageDlg(response.StatusMessage, mtError, [mbOk], 0);
我发现部分解决了我的问题。我可以设置值 Rate 调用电话 Rate.SetAsString(const val: WideString) (fragment 2, line: 01)
但出现其他问题。当可变利率小数部分为零时,Estimate 被添加到 QuickBooks 中。
如果小数部分不为零(例如:rate := 23.10),当调用 SetAsString 过程时,我的应用程序中会出现异常。
和错误消息:“无效的价格值”。
问题 #2:为什么我不能用小数部分评分?
片段 2:
01: estimateLineAdd.ORRate.Rate.SetAsString(FloatToStr(rate));
如果我尝试将过程参数更改为字符串值:
estimateLineAdd.ORRate.Rate.SetAsString('23.21') 我有第一个问题的错误。
如果我尝试将过程参数更改为:
estimateLineAdd.ORRate.Rate.SetAsString('23,21')
我收到相同的异常和错误消息:“无效的价格值”。
可以理解,分隔符是'.'反而 ','。
最佳答案
delimeter is '.' instead ','.
我有同样的问题,因为 QB 在
,
的机器上运行被用作分隔符,不支持:https://community.intuit.com/questions/1012431-how-to-change-number-formatting-decimal-and-grouping-separators我在 Windows 中的区域设置设置为 ru-RU 区域设置,因此 QB 将价格显示为“60,12”。
似乎 QBFC 除外
.
:queryRq.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.SetAsString("60,12"); // this immediatly throws
queryRq.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.SetAsString("60.12"); // this is OK
当我执行“获取所有项目”请求时,QB 以
,
返回价格,(根据地区设置):<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<ItemServiceQueryRs requestID="0" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<ItemServiceRet>
...
<SalesOrPurchase>
<Price>60,07</Price>
但是
obj.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.GetValue();
返回 60
无一异常(exception)。真正奇怪的是(在我手动修复从 sendRequestXML 返回的 xml 字符串之后)也不是
,
都不是.
接受了我的 QuickBooks Pro 2017!在 receiveResponseXML 我得到:<ItemServiceAddRs requestID=\"0\" statusCode=\"3045\" statusSeverity=\"Error\" statusMessage=\"There was an error when converting the price "60.12"
and
<ItemServiceAddRs requestID=\"0\" statusCode=\"3045\" statusSeverity=\"Error\" statusMessage=\"There was an error when converting the price "60,12"
在我将设置更改为 en-US(对于 QB Pro US)后,所有设置都适用于“60.12”。
关于delphi - 如何在我的应用程序中为新估算的项目设置值(value)率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27211458/