[omniORB] Fw: (by abcluo@163.com)use sequence<struct> problem ?

roger abcluo at 163.com
Tue Oct 17 00:24:18 BST 2006


 
HI!

I am download omniORB-4.0.7-win32-vc7.zip,
I am using omniORB_4.0.7 on  Win2000 (MSVC++7.1) platforms,
and the echo examples work fine .
Now I use data sequence,but have the problem :

//----------IDL---------
struct NetDataItem
{
 long id;
 string name;
};
typedef sequence<NetDataItem> DataArray; 
typedef sequence<long> DataLongArray;
interface QDataSeq
{
 DataArray QueryDatas(); 
 DataLongArray QueryLongData(); 
};

//---------server code--------------
// return  struct data Sequence
DataArray* QDataSeq_i::QueryDatas(){
 int cnt =100;
 DataArray_var datas = new DataArray((CORBA::Long)cnt);
 datas->length(cnt);
 for (int i =0;i< cnt; ++i)
 {
  datas[i].id = (CORBA::Long)(i+1);
  datas[i].name = CORBA::string_dup("aaaa"); // is OK??
 }
 std::cout << "OK" << endl;
 return datas._retn();
}
// return long Sequence
DataArray* QDataSeq_i::QueryLongData(){
 int cnt =100;
 DataLongArray_var datas = new DataLongArray((CORBA::Long)cnt);
 datas->length(cnt);
 for (int i =0;i< cnt; ++i)
 {
  datas[i] = (CORBA::Long)(i+1);
 }
 std::cout << "OK" << endl;
 return datas._retn();
}

//-----------client code-----------------------
this arises some exception of free sequence. why?
//query struct data Sequence , use _var
void queryData(QDataSeq_ptr e)
{
 DataArray_var dest = e->QuearyDatas();
 int len = pdest->length();
 std::cerr << "query sequence size £º" << len << endl;
 //do something
}
/* use delete sequence ptr
void queryData(QDataSeq_ptr e)
{
 DataArray* pdest = e->QuearyDatas();
 int len = pdest->length();
 std::cerr << "query sequence size £º" << len << endl;
 //pdest->release();  
 delete pdest; // arise some exception. 
                   //If this isn't used 'delete' , it have memory leak,but run OK.
}
*/

//query long Sequence. It is work fine and not have memory leak. 
void queryData(QDataSeq_ptr e)
{
 DataArray_var dest = e->QuearyDatas();
 int len = pdest->length();
 std::cerr << "query sequence size £º" << len << endl;
 //do something
}
====================================
Get a list of NetDataItem and display it, ERROR IN THE CLIENT.
but Get a list of long ,it work fine.
why?
Help me!  
How to fine use sequence of struct in the client and server?
 
2006-10-16 roger007
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20061016/b6327e0b/attachment.htm


More information about the omniORB-list mailing list