'Could not convert variant of type (Array Byte) into type (Integer)

来源:互联网 发布:二战法国投降 知乎 编辑:程序博客网 时间:2024/05/22 15:27

This is actually a report for ExpressQuantumGrid Suite (not ExpressEditors Library) but it is not obvious how to change the Product/Technology on the Edit Issue page after the ticket has already been created.

The following exception occurs in TcxGrid when trying to select multiple cells using the mouse using drag operations.

'Could not convert variant of type (Array Byte) into type (Integer)'

I attached a simpler project that includes all the necessary files for reproducing the error. It also includes a screenshot with the error message.

This error occurs in on line 8939 in cxCustomTableView.pas, in the method TcxCustomGridTableController.IsPullFocusingPosChanged. It only happens in grid mode, with cell multi-select enabled, when FPullFocusingRecordId is a byte array variant.

This might actually be a bug in the Delphi RTL that is not able to compare two byte array variants. I implemented the following simple workaround in cxCustomTableView.pas and this fixed the error:

function SameRecordID(V1, V2: Variant): Boolean;
var
  I: Integer;
begin
  if VarIsArray(V1) and VarIsArray(V2) then
  begin
    if (VarArrayLowBound(V1, 1) = VarArrayLowBound(V2, 1)) and (VarArrayHighBound(V1, 1) = VarArrayHighBound(V2, 1)) then
      for I := VarArrayLowBound(V1, 1) to VarArrayHighBound(V1, 1) do
      if V1[I] <> V2[I] then
      begin
        Result := False;
        Exit;
      end;
    Result := True;
  end
  else
    Result := V1 = V2;
end;

function TcxCustomGridTableController.IsPullFocusingPosChanged: Boolean;
begin
  Result := not SameRecordID(FPullFocusingRecordId, DataController.GetRowId(FocusedRecordIndex)) or
    (FPullFocusingItem <> FocusedItem);
end;

The error does not occur when DataModeController.GridMode is False, because in this case the two record IDs being compared are two integers.

I really hope you will be able to reproduce it this time. Please let me know if you need more information.