關於FAST Report 6 交叉報表顯示帶中文的StringGrid報UnicodeString 不能轉換為 Double的錯誤解決方法
問題原因是FastReport例項中,Cross元件的合計項未關閉,雙擊“frxReport1”進入如下圖所示編輯介面:
編輯Cross1元件,Cell 選擇 無,即可解決。
問題的跟蹤:
通過跟蹤原始碼,發現報錯的函式為 frxCross下的 AddFuncValues,當執行到 cfSum:時,如內容含有中文,那麼 h.FFuncValues[i] := h.FFuncValues[i] + Values[i]; 這一語句中 Values[i] 做隱式轉換時將報錯。
procedure TfrxCrossHeader.AddFuncValues(const Values, Counts: array of Variant;
const CellFunctions: array of TfrxCrossFunction);
var
i: Integer;
h: TfrxCrossHeader;
begin
{ add aggregate values for this cell and all its parent cells }
h := Self;
while h <> nil do
begin
for i := 0 to FCellLevels - 1 do
if Values[i] <> Null then
case CellFunctions[i] of
cfNone:;
cfSum:
h.FFuncValues[i] := h.FFuncValues[i] + Values[i];
cfMin:
if (h.FFuncValues[i] = Null) or (Values[i] < h.FFuncValues[i]) then
h.FFuncValues[i] := Values[i];
cfMax:
if (h.FFuncValues[i] = Null) or (Values[i] > h.FFuncValues[i]) then
h.FFuncValues[i] := Values[i];
cfAvg:
begin
h.FFuncValues[i] := h.FFuncValues[i] + Values[i];
h.FCounts[i] := h.FCounts[i] + Counts[i];
end;
cfCount:
h.FFuncValues[i] := h.FFuncValues[i] + Values[i];// + Counts[i];
end;
h := h.Parent;
end;
end;