creating Dynamic any from TypeCode

creating Dynamic any from TypeCode

Post by Tom » Wed, 16 Jul 2003 18:06:42



  Hi All,

  I created a dynamic any from TypeCode by calling this operation
 create_dynamic_any_from_type_code(TypeCode).
When i try to insert value in this any, it is causing some problem.
Even when i try to print the component count it gives 0.
Example is given below-

  #include <OB/CORBA.h>
  int main(int argc, char *argv[])
  {
 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
   CORBA::Object_var obj =
orb->resolve_initial_references("DynAnyFactory");
    DynamicAny::DynAnyFactory_var dafact
  = DynamicAny::DynAnyFactory::_narrow(obj);

  try {
  CORBA::ValueMemberSeq mems(2);
 CORBA::Any_var result;
 CORBA::Long value1 = 99;
CORBA::Boolean value2 = 1;
  mems.length(2);
 mems[0].name = CORBA::string_dup("member1");
 mems[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_long);
 mems[0].access = 1;
 mems[1].name = CORBA::string_dup("member2");
 mems[1].type = CORBA::TypeCode::_duplicate(CORBA::_tc_boolean);
 mems[1].access = 1;
CORBA::TypeCode_ptr new_tc = orb->create_value_tc(
"IDL:People/SSN:1.0", "SSN", 0, CORBA::TypeCode::_nil(), mems
   );

  DynamicAny::DynAny_ptr dyn_struct =
  dafact->create_dyn_any_from_type_code(new_tc);
   dyn_struct->insert_long(value1);   // This line is giving problem
   dyn_struct->next();
  dyn_struct->insert_boolean(value2);

result = dyn_struct->to_any();
 dyn_struct->destroy();
 CORBA::release(dyn_struct);
     }
    catch(CORBA::SystemException &e)
    {
     cout << e << endl;
        }
        }

  thanks in advance
Tom

 
 
 

creating Dynamic any from TypeCode

Post by Brian Kel » Wed, 16 Jul 2003 22:32:46


Quote:>   I created a dynamic any from TypeCode by calling this operation
>  create_dynamic_any_from_type_code(TypeCode).
> When i try to insert value in this any, it is causing some problem.
> Even when i try to print the component count it gives 0.
> Example is given below-

What error do you get? Is it a compile or runtime error?
Also, what ORB, platform, OS and compiler are you using?

Cheers,
Brian
IONA Technologies

Quote:>   #include <OB/CORBA.h>
>   int main(int argc, char *argv[])
>   {
>  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
>    CORBA::Object_var obj =
> orb->resolve_initial_references("DynAnyFactory");
>     DynamicAny::DynAnyFactory_var dafact
>   = DynamicAny::DynAnyFactory::_narrow(obj);

>   try {
>   CORBA::ValueMemberSeq mems(2);
>  CORBA::Any_var result;
>  CORBA::Long value1 = 99;
> CORBA::Boolean value2 = 1;
>   mems.length(2);
>  mems[0].name = CORBA::string_dup("member1");
>  mems[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_long);
>  mems[0].access = 1;
>  mems[1].name = CORBA::string_dup("member2");
>  mems[1].type = CORBA::TypeCode::_duplicate(CORBA::_tc_boolean);
>  mems[1].access = 1;
> CORBA::TypeCode_ptr new_tc = orb->create_value_tc(
> "IDL:People/SSN:1.0", "SSN", 0, CORBA::TypeCode::_nil(), mems
>    );

>   DynamicAny::DynAny_ptr dyn_struct =
>   dafact->create_dyn_any_from_type_code(new_tc);
>    dyn_struct->insert_long(value1);   // This line is giving problem
>    dyn_struct->next();
>   dyn_struct->insert_boolean(value2);

> result = dyn_struct->to_any();
>  dyn_struct->destroy();
>  CORBA::release(dyn_struct);
>      }
>     catch(CORBA::SystemException &e)
>     {
>      cout << e << endl;
>         }
>         }

>   thanks in advance
> Tom