Board index » delphi » nil value for integer

nil value for integer


2007-06-12 09:47:02 AM
delphi158
We have a web service that returns an array of objects which are
populated from a db. One (or more) or the properties may contain null
values.
The web service was developed in Java/Eclipse (using Axis). Both JAX-WS
clients and the SOAP-UI environment accept the data from the service.
In Delphi an exception EConvertError occurs and the data is not
available to the calling procedure/function. We first saw this in a
test application written using Delphi2006. I tried it with Delphi2007
today and got the same result.
Thoughts?
 
 

Re:nil value for integer

Quote
Thoughts?
Most likely you are using variants for the returned data.
In this case the special cases - unassigned and empty have to
be dealt with explicitly before a conversion to another data type
is tried. Variant is the only variable type which can deal with these
cases, therefore the exception.
Regards from Germany
Franz-Leo
 

Re:nil value for integer

Quote
Most likely you are using variants for the returned data.
No, I am not using variants in my own code (and I am relatively sure
that's not what the WSDL importer is generating but I will take a second
look; mostly Java lately).
Here's what seems to address it OK (I threw in the int64 for good measure):
Comparing files OPToSOAPDomConv.pas.orig and OPTOSOAPDOMCONV.PAS
***** OPToSOAPDomConv.pas.orig
begin
I := StrToInt(SoapData);
SetOrdProp(Instance, PropInfo, I);
***** OPTOSOAPDOMCONV.PAS
begin
try
I := StrToInt(SoapData);
except
on EConvertError do I := 0;
end;
SetOrdProp(Instance, PropInfo, I);
*****
***** OPToSOAPDomConv.pas.orig
begin
I64 := StrToInt64(SoapData);
SetInt64Prop(Instance, PropInfo, I64);
***** OPTOSOAPDOMCONV.PAS
begin
try
I64 := StrToInt64(SoapData);
except
on EConvertError do I := 0;
end;
SetInt64Prop(Instance, PropInfo, I64);
*****
I don't like the idea of "losing" the nil/null value from the DB but if
it's not supported...
I think I bumped into some other code where Variants have the
same/similar issue but I may have the modules mixed up. I think there
is also an earlier discuss here that might shed more light on this issue
but at some point I got confused about if a client, server, or both were
being built in Delphi (but then it was late).
 

Re:nil value for integer

On Tue, 12 Jun 2007 09:16:30 -0400, "Carl J. Mosca"
<XXXX@XXXXX.COM>writes:
Quote
>Most likely you are using variants for the returned data.

No, I am not using variants in my own code (and I am relatively sure
that's not what the WSDL importer is generating but I will take a second
look; mostly Java lately).
StrToInt doesn't like empty strings. You should try StrToIntDef.
Regards from Germany
Franz-Leo
 

Re:nil value for integer

Quote

StrToInt doesn't like empty strings. You should try StrToIntDef.

You mean the Borland (uh I mean CodeGear) developers should. that is not
my code. :)
Check the module name (in the source\win32\soap directory if I am
recalling correctly).
 

Re:nil value for integer

Hello,
Support for 'nil' has been an ongoing issue. Several built-in types of
Delphi are not nullable. So we opted to use a class for these cases (not
elegant but it works). So with the latest update for Delphi 2007 I have added
several TXSxxxx types to help with this. Basically: TXSBoolean, TXSInteger,
TXSLong, etc. TXSString was already there but it was not registered. Now it
is.
When importing a WSDL you must enable the Use 'TXSString for simple nillable
types' option to make the importer switch to TXSxxxx types. On the command
line it is the "-0z+" option.
I don't consider the 'nillable' issue solved as there are cases that are
still not handled currently. For example, enumerations can be nillable also.
For that case, the importer will have to generate a TXSxxx type based on the
underlying enumeration. Generics would be great for this (a la C#'s
System.Nullable<T>) but we'll probably solve this before/without generics to
support all versions.
What version of the runtime/importer are you using? If you have Delphi 2007 please
grab the latest update. If you're using an earlier version, I plan to update
the runtime/importer post in CodeCentral with the latest updates soon. Let
me know how I can help.
Cheers,
Bruneau.
 

Re:nil value for integer

I forgot to mention that with the latest updated I have also tweaked the
runtime to handle cases where the 'native' side expects 'int', 'string' (and
other non-nullable types) and the XML side sends a nil node. Basically,
we'll default to initializing the native with default values.
The following is an excerpt from TypeTrans.pas with the relevant portion:
function TTypeTranslator.CastSoapToNative(Info: PTypeInfo; const SoapData:
WideString; NatData: Pointer; IsNull: Boolean): Boolean;
const
sDefaultValues: array[TTypeKind] of WideString = (
{tkUnknown}'', {tkInteger}'0', {tkChar}#0, {tkEnumeration}'',
{tkFloat}'0', {tkString}'', {tkSet}'', {tkClass}'',
{tkMethod}'', {tkWChar}#0, {tkLString}'', {tkWString}'',
{tkVariant}'', {tkArray}'', {tkRecord}'', {tkInterface}'',
{tkInt64}'0', {tkDynArray}''
);
function Check(const SoapData: WideString): WideString;
begin
if not IsNull then
Result := Trim(SoapData)
else
Result := sDefaultValues[Info^.Kind];
end;
If you run into a case where we attempt to convert an empty string to an
integer or something similar please let me know.
Cheers,
Bruneau.
 

Re:nil value for integer

Quote
We have a web service that returns an array of objects which are
populated from a db. One (or more) or the properties may contain null
values.

The web service was developed in Java/Eclipse (using Axis). Both JAX-WS
clients and the SOAP-UI environment accept the data from the service.

In Delphi an exception EConvertError occurs and the data is not
available to the calling procedure/function. We first saw this in a
test application written using Delphi2006. I tried it with Delphi2007
today and got the same result.

Thoughts?
Hello,
can we hope to get the -0z+ option and runtime support in the "backported" SOAP library for D7?
Regards,
Jaka
BizTalk Utilities - Frustration free BizTalk Adapters
www.topxml.com/biztalkutilities