AnnLoadArray example for C++ Builder

Note:

This topic is for Document/Medical only.

//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::AnnLoadArrayClick(TObject *Sender)
{
   long lCount;
   HFILE hFile;
   HGLOBAL hData=NULL;
   char * pData=NULL;
   ILEADRasterVariant* pRasterVarBuffer= NULL;

   CoCreateInstance( CLSID_LEADRasterVariant,
                     NULL,
                     CLSCTX_ALL,
                     IID_ILEADRasterVariant,
                     (void**)&pRasterVarBuffer);
   if ( pRasterVarBuffer )
   {
      hFile = _lopen("c:\\test.ann", OF_READ);
      lCount = _llseek(hFile, 0, SEEK_END);
      _llseek(hFile, 0, SEEK_SET);
      hData = GlobalAlloc(GMEM_MOVEABLE, lCount);
      pData = (char*)GlobalLock(hData);

      _lread(hFile, pData, lCount);

      pRasterVarBuffer->set_Type( VALUE_ARRAY_BYTE );
      pRasterVarBuffer->ItemCount= lCount;

      for ( int i= 0; i < lCount; i ++ )
      {
         pRasterVarBuffer->set_ShortItemValue( i, (short)pData[i] );
      }
      GlobalUnlock(hData);
      GlobalFree(hData);

      pRasterAnn->AnnLoadArray( pRasterVarBuffer, lCount, 1 );
      _lclose(hFile);

      if ( pRasterVarBuffer )
      {
         pRasterVarBuffer->Release();
         pRasterVarBuffer= NULL;
      }
   }

}