Convert Object -> Numeric

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Convert Object -> Numeric

Post by robert »

I would write

Code: Select all

if npgresult IS Decimal
     nValue:= (int)npgresult // No need to try with Value property.
endif
Robert

PS In the next build you can also use the IS pattern

Code: Select all

IF npgResult is Decimal dValue
   // now there is a local dValue of type Decimal with the value from npgResult
  nValue := (INT) dValue   // the compiler now knows that you are converting a decimal to an int
endif
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Frank Müßner
Posts: 280
Joined: Sat Dec 12, 2015 2:22 pm
Location: Germany

Convert Object -> Numeric

Post by Frank Müßner »

Hi Johann;
lumberjack wrote: Ok I understand, why still VO usual?
PS: My German is improving... :)
because i don´t know what i am getting from the select. :-(

Historie:
In VO Code, i use (VO2ADO) Adoserver to get one Value from a Table. Then i get with AdoServer:RecordSet:Fields:Item(1):Type, the Type of the Column an can handle and modify this.

When Transport to X# i try to replace this with .Net Postgresql Provide, only for this type of getting one Value from Table.
and there comes the Problem with getting the right DataType. Sample, Decimals come as Object.

But i have with Karl-Heinz code solve this.



@ Robert,
if npgresult IS Decimal
nValue:= (int)npgresult // No need to try with Value property.
endif
not work, because npgresult is Object. when get Numeric Values from PG.

But i have now solved the Problem with Karl-Heinz Code.
Perhaps some not work, because i have VN3 Runtime.
I wait for VX2ADO and then use the X# Runtime, and try to transport my main App. :-)
Regards, Frank
Post Reply