AnnSaveArray example for C++ Builder

Note:

This topic is for Document/Medical only.

'Please note the following:
'LEADRasterView1 refers to a LEADRasterView control
//Global declarations
LEADRasterAnnotation * pRasterAnn= NULL;
LEADRasterAnnToolBar* pRasterAnnToolbar= NULL;
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   CoCreateInstance(CLSID_LEADRasterAnnotation, NULL, CLSCTX_ALL, IID_ILEADRasterAnnotation, (void**)&pRasterAnn);
   CoCreateInstance(CLSID_LEADRasterAnnToolBar, NULL, CLSCTX_ALL, IID_ILEADRasterAnnToolBar, (void**)&pRasterAnnToolbar);
   pRasterAnn->AnnParentRasterView = LEADRasterView1->Raster;
   LEADEventSink1->Connect (pRasterAnn, DIID__LEADRasterAnnotationEvents);
   pRasterAnn->AnnUserMode = ANN_USERMODE_DESIGN ;
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
   if (pRasterAnn)
      pRasterAnn->Release ();
   if (pRasterAnnToolbar)
      pRasterAnnToolbar-> Release();
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
   long lSize;
   HFILE hFile;
   char * pData= NULL;
   ILEADRasterVariant* pRasterVarBuffer= NULL;

   CoCreateInstance( CLSID_LEADRasterVariant,
                     NULL,
                     CLSCTX_ALL,
                     IID_ILEADRasterVariant,
                     (void**)&pRasterVarBuffer);
   if ( pRasterVarBuffer )
   {
      pRasterAnn->AnnSaveArray(ANN_FMT_NATIVE, true, pRasterVarBuffer, SAVE_OVERWRITE, 0);
      lSize = pRasterVarBuffer->ItemCount;

      _lcreat("c:\\test.ann", 0);
      hFile = _lopen("c:\\test.ann", OF_READWRITE);
      pData= (char*) GlobalAlloc(GHND, lSize );
      if ( pData )
      {
         for (int i= 0; i < lSize; i ++)
         {
            pData[i]= pRasterVarBuffer->get_ShortItemValue(i);
         }
         _lwrite(hFile, (LPCSTR)pData, lSize);
         _lclose(hFile);
         GlobalFree (pData);
      }
        if ( pRasterVarBuffer )
      {
         pRasterVarBuffer->Release();
         pRasterVarBuffer= NULL;
      }
   }
}