Board index » delphi » Why? -> "Constant expression violates subrange bounds"

Why? -> "Constant expression violates subrange bounds"


2003-08-26 04:15:07 AM
delphi186
The below code (using D5 and an Office 2000 Excel_TLB file) works just fine.
However, it compiles with this warning:
"Constant expression violates subrange bounds"
for this line:
R.Borders.Item[xlEdgeBottom].Weight := xlMedium;
Why? xlMedium seems to be a valid value.
(The unit has dozens of these warnings and I don't want them to come back
and bite me!)
TIA,
Karl
procedure TForm1.btnCreateExcelAppClick(Sender: TObject);
var
Excel: _Application;
LCID: Integer;
R: Range;
begin
LCID := GetUserDefaultLCID;
Excel := CoExcelApplication.Create;
Excel.Visible[LCID] := True;
Excel.Workbooks.Add( EmptyParam, LCID );
R := Excel.Range[ 'A1', 'B1' ];
R.Borders.Item[xlEdgeBottom].LineStyle := xlDashDot;
R.Borders.Item[xlEdgeBottom].Weight := xlMedium; <- D5 warning here
end;
 
 

Re:Why? -> "Constant expression violates subrange bounds"

It has to do with signed vs. unsigned integer - e.g. assigning $FFFFFFFF to
an integer variable will produce this warning, since $FFFFFFFF is out of the
range for a signed integer (-$80000000 <->$7FFFFFFFFF ).
You can avoid this by typecasting:
R.Borders.Item[xlEdgeBottom].Weight := integer(xlMedium);
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Karl Thompson" <XXXX@XXXXX.COM>writes
Quote


The below code (using D5 and an Office 2000 Excel_TLB file) works just
fine.
However, it compiles with this warning:

"Constant expression violates subrange bounds"

for this line:

R.Borders.Item[xlEdgeBottom].Weight := xlMedium;

Why? xlMedium seems to be a valid value.

(The unit has dozens of these warnings and I don't want them to come back
and bite me!)

TIA,
Karl


procedure TForm1.btnCreateExcelAppClick(Sender: TObject);
var
Excel: _Application;
LCID: Integer;
R: Range;
begin
LCID := GetUserDefaultLCID;
Excel := CoExcelApplication.Create;
Excel.Visible[LCID] := True;
Excel.Workbooks.Add( EmptyParam, LCID );

R := Excel.Range[ 'A1', 'B1' ];
R.Borders.Item[xlEdgeBottom].LineStyle := xlDashDot;
R.Borders.Item[xlEdgeBottom].Weight := xlMedium; <- D5 warning here
end;