Delphi export to Excel - false errors in IDE for code that compiles

Viewed 252

When coding for Excel in Delphi 10.3.3, I get false errors in the IDE for code that compiles and works just fine.

The error messages...

Undeclaired identifier 'Range' at line xxx
Undeclaired identifier 'Cells' at line xxx

...for every occurrence of the two excel variables.

Here's the complete code:

procedure tmainform.ExportToExcel;
var
  xls, wb, MyRange, CompletionRow: OLEVariant;
  arrData: Variant;
  ColCount, CurrRow, CurrCol: Integer;
begin
  ColCount:= 6;
  arrData:= VarArrayCreate([1, TotOrders+1, 1, ColCount], varVariant);

  for CurrCol:= 1 to ColCount do case currcol of
     1: arrData[1,1]:= 'ORDER#';
     2: arrData[1,2]:= 'DATE';
     3: arrData[1,3]:= 'ITEM';
     4: arrData[1,4]:= 'QTY';
     5: arrData[1,5]:= 'COST';
     6: arrData[1,6]:= 'RECEIVED?';
  end;

  for CurrRow:= 1 to TotOrders do begin
     for CurrCol:= 1 to ColCount do begin
        case currcol of
           1: arrData[CurrRow+1,1]:= Orders[1].Number;
           2: arrData[CurrRow+1,2]:= Orders[2].Date;
           3: arrData[CurrRow+1,3]:= Orders[3].Name;
           4: arrData[CurrRow+1,4]:= Orders[4].Qty;
           5: arrData[CurrRow+1,5]:= Orders[5].Cost;
           6: arrData[CurrRow+1,6]:= Orders[6].Received;
        end;
     end;
  end;

  xls:= CreateOLEObject('Excel.Application');
  wb:= xls.Workbooks.Add;
{THIS LINE}  MyRange:= wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1],wb.WorkSheets[1].Cells[TotOrders+1, ColCount]];     // THIS LINE
  MyRange.Value:= arrData;
  MyRange.EntireColumn.Autofit;
{THIS LINE}  CompletionRow:= wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1],wb.WorkSheets[1].Cells[1, ColCount]];     // THIS LINE
  CompletionRow.font.bold := true;
{THIS LINE}  CompletionRow:= wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[2, 5],wb.WorkSheets[1].Cells[TotOrders+1, 5]];     // THIS LINE
  CompletionRow.NumberFormat:= '$#,##0.00';
  xls.Visible:= True;
  xls.ActiveWindow.Activate;
end;

Global variables are:

  Orders: array of ordertype;
  TotOrders: integer;

Again, this code runs and works just fine, but I'd like to get rid of those fake errors always showing in the upper left.

fake errors - code compiles

1 Answers

It is a known bug in Delphi. There is nothing you can do except upgrade to version "10.4 Sydney" (or later) Reference.

Related