[omniORB] insert data to union

Duncan Grisby duncan at grisby.org
Mon Jul 16 19:55:38 BST 2007


On Monday 16 July, "Zsolt SZALAI" wrote:

> I'm using omniorb 4.0.x. It always throws TypeMismatch exception(at
> codeline marked with *) when i would like to insert data into an enum.

I haven't looked really closely at your code, but this looks fishy...

[...]
>    DynamicAny::DynAny_ptr disc = daf->create_dyn_any_from_type_code(_tc_swtype());
> 
>    DynamicAny::DynUnion_ptr dUnion = DynamicAny::DynUnion::_narrow(dv);
>    DynamicAny::DynEnum_ptr edisc = DynamicAny::DynEnum::_narrow(disc);

You've created a DynAny with the right type for the discriminator, but
it's not the union's discriminator...

>    disc = dUnion->get_discriminator();

Here you're getting the actual discriminator from the union.

>    if (selected == 0) {
>       edisc->set_as_ulong(0); //swtype

And now you're setting the one that isn't the union's discriminator. It
doesn't matter because it defaults to that case.

>       DynamicAny::DynAny_ptr dm = dUnion->member();
>       dm->insert_long(5);
>    }
>    if (selected == 1) {
>      edisc->set_as_ulong(1); //swtype

Now you're setting the wrong thing again, but this time the default is
wrong.

>      DynamicAny::DynAny_ptr dm = dUnion->member();
> *    dm->insert_string("FOOBAR");

I think it'll probably work if you rearrange the code so that edisc is
the union's discriminator, not some other unrelated DynEnum.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list