Board index » delphi » Ordinal type required

Ordinal type required

When I call the below funciton, I get the error "ordinal type required"
Anyone know what I am doing wrong here????

function InchToDecimal(Inches : single) : single;

begin
case Inches of
  0: Result := 0;
  1: Result := 0.08333;
  2: Result := 0.16667;
  3: Result := 0.25;
  4: Result := 0.33333;
  5: Result := 0.41667;
  6: Result := 0.5;
  7: Result := 0.58333;
  8: Result := 0.66667;
  9: Result := 0.75;
  10: Result := 0.83333;
  11: Result := 0.91667
  end;
  InchToDecimal := Result;
end;

 

Re:Ordinal type required


Hi Dan !

First, it is not related to databases. Rather to Delphi language.

The problem is "Inches" is float point value. Ordinal types are
Int64 (not sure), Integer, SmallInt, ShortInt, Byte, Char, enums
(may be i miss something). So, your function should be (either
either):

1) > function InchToDecimal(Inches : single) : single;
function InchToDecimal(Inches : Integer) : single;

2)> case Inches of
case Trunc(Inches) of

Regards,
Dmitry

--
Dmitry Arefiev - www.da-soft.com
   AnyDAC - Oracle, MySQL, MSSQL, MSAccess, IBM DB2, Sybase
      ASA, DbExpress, ODBC freeware data access framework
gs-soft AG - www.gs-soft.com
   SAPx - Delphi to SAP R/3 direct access
   Saphir - SAP R/3 metadata at your fingertips
   MetaBase - ERWIN model in Delphi applications

Re:Ordinal type required


"Dan Rock" <danno492_NOS...@hotmail.com> wrote

Quote
> When I call the below function, I get the error "ordinal
> type required" Anyone know what I am doing wrong here?
>   function InchToDecimal(Inches : single) : single;
>   begin
>     case Inches of ...

Yes.  Floating binary-point type single is *not* an
"ordinal" type.  Ordinal types can represent numbers
like 0, 1, ... 11, and 12; but not 1.5.  Read the definition
of "Ordinal types" in the help file.

If you can change you your program to use
  function InchToDecimal(Inches : integer) : single;
then it would work.

Regards, JohnH

Re:Ordinal type required


Thank you folks, I have trouble sometimes finding this information in the
help file.

Quote
"Dan Rock" <danno492_NOS...@hotmail.com> wrote in message

news:42b56fdd$1@newsgroups.borland.com...
Quote
> When I call the below funciton, I get the error "ordinal type required"
> Anyone know what I am doing wrong here????

> function InchToDecimal(Inches : single) : single;

> begin
> case Inches of
>  0: Result := 0;
>  1: Result := 0.08333;
>  2: Result := 0.16667;
>  3: Result := 0.25;
>  4: Result := 0.33333;
>  5: Result := 0.41667;
>  6: Result := 0.5;
>  7: Result := 0.58333;
>  8: Result := 0.66667;
>  9: Result := 0.75;
>  10: Result := 0.83333;
>  11: Result := 0.91667
>  end;
>  InchToDecimal := Result;
> end;

Other Threads