Thread View: borland.public.delphi.rtl.general
3 messages
3 total messages
Started by iamsunix
Wed, 17 Jan 2007 07:22
How to support decimal type of variant
Author: iamsunix
Date: Wed, 17 Jan 2007 07:22
Date: Wed, 17 Jan 2007 07:22
23 lines
1519 bytes
1519 bytes
In delphi7, I see some codes in system.pas
//varDecimal = $000E; { vt_decimal 14 } {UNSUPPORTED as of v6.x code
base}
It seem that delphi7 does not support decimal type of variant.
:(
Now, I use ADOInt._Recordset to open a recordset from MS SQLServer, my
recordset(var RS: _Recordset) include one field(FieldName is 'Amount') which
fieldType is adDecimal(declare in adoint.pas), but it is not supported by
delphi7. the follwing codes will raise exception:
if RS.Field['Amount'].Value > 0 then //raise exception
begin
...
end;
How can I do? How can I make delphi7 support vardecimal? why delphi7 remove
vardecimal type of Variant?
Thanks!!!
Re: How to support decimal type of variant
Author: Peter Below TeamB
Date: Thu, 18 Jan 2007 18:28
Date: Thu, 18 Jan 2007 18:28
65 lines
2750 bytes
2750 bytes
iamsunix wrote:
> In delphi7, I see some codes in system.pas
>
> //varDecimal = $000E; { vt_decimal 14 } {UNSUPPORTED as of v6.x
> code base}
>
> It seem that delphi7 does not support decimal type of variant.
>
> :(
>
> Now, I use ADOInt._Recordset to open a recordset from MS SQLServer, my
> recordset(var RS: _Recordset) include one field(FieldName is
> 'Amount') which fieldType is adDecimal(declare in adoint.pas), but it
> is not supported by delphi7. the follwing codes will raise exception:
>
> if RS.Field['Amount'].Value > 0 then //raise exception
> begin
> ...
> end;
>
> How can I do? How can I make delphi7 support vardecimal? why delphi7
> remove vardecimal type of Variant?
It did not remove it, you misinterpret the comment. It was never
supported by Delphi, D5 did not even define a constant for it.
DECIMAL is not an automation-compatible data type, MS added it
specifically for SQL Server support via ADO.
It is possible to work with unsupported variant types in Delphi, but it
is cumbersome. The first thing you have to do is test the actual data
type of the variant.
uses ActiveX; // this unit declares the API functions for variant
manipulation
var
V: OleVariant;
Value: Double;
...
V:= RS.Field['Amount'];
if VarType(V) = varDecimal then begin
OleCheck(VarR8FromDec(TVarData(V).varAny, Value));
if value > 0 then
....
end;
This technique becomes particularly painful when the automatic variant
cleanup Delphi does on V above blows up as well. In such a case you
have to call
VariantClear(V);
explicitely.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Re: How to support decimal type of variant
Author: iamsunix
Date: Mon, 22 Jan 2007 01:29
Date: Mon, 22 Jan 2007 01:29
70 lines
2995 bytes
2995 bytes
Thank you very much:)
"Peter Below (TeamB)" <none>
??????:xn0f1d5746ifs300a@newsgroups.borland.com...
> iamsunix wrote:
>
>> In delphi7, I see some codes in system.pas
>>
>> //varDecimal = $000E; { vt_decimal 14 } {UNSUPPORTED as of v6.x
>> code base}
>>
>> It seem that delphi7 does not support decimal type of variant.
>>
>> :(
>>
>> Now, I use ADOInt._Recordset to open a recordset from MS SQLServer, my
>> recordset(var RS: _Recordset) include one field(FieldName is
>> 'Amount') which fieldType is adDecimal(declare in adoint.pas), but it
>> is not supported by delphi7. the follwing codes will raise exception:
>>
>> if RS.Field['Amount'].Value > 0 then //raise exception
>> begin
>> ...
>> end;
>>
>> How can I do? How can I make delphi7 support vardecimal? why delphi7
>> remove vardecimal type of Variant?
>
> It did not remove it, you misinterpret the comment. It was never
> supported by Delphi, D5 did not even define a constant for it.
> DECIMAL is not an automation-compatible data type, MS added it
> specifically for SQL Server support via ADO.
>
> It is possible to work with unsupported variant types in Delphi, but it
> is cumbersome. The first thing you have to do is test the actual data
> type of the variant.
>
> uses ActiveX; // this unit declares the API functions for variant
> manipulation
>
> var
> V: OleVariant;
> Value: Double;
>
> ...
> V:= RS.Field['Amount'];
> if VarType(V) = varDecimal then begin
> OleCheck(VarR8FromDec(TVarData(V).varAny, Value));
> if value > 0 then
> ....
> end;
>
> This technique becomes particularly painful when the automatic variant
> cleanup Delphi does on V above blows up as well. In such a case you
> have to call
>
> VariantClear(V);
>
> explicitely.
>
>
>
> --
> Peter Below (TeamB)
> Don't be a vampire (http://slash7.com/pages/vampires),
> use the newsgroup archives :
> http://www.tamaracka.com/search.htm
> http://groups.google.com
> http://www.prolix.be
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads