AnnGetPoint... 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();
}

/*In the AnnDrawn event, this example checks to see if the annotation object is a polygon.
If it is a polygon, the example gets the number of points that define the object;
then it gets the arrays of X and Y coordinates and displays the points in a message box.*/
void __fastcall TForm1::LEADEventSink1Invoke(TObject *Sender, int DispID,
      const TGUID &IID, int LocaleID, WORD Flags, tagDISPPARAMS &Params,
      Pointer varResult, Pointer ExcepInfo, Pointer ArgErr)
{
   int hAnnObject;
   AnnObjectType nType;

   int i;
   ILEADRasterVariant* pRasterVarX;  //array for the X coordinates
   ILEADRasterVariant* pRasterVarY;  //array for the Y coordinates
   long nPoints;     //number of points in the object
   AnsiString msgStr;
   float x, y;

   CoCreateInstance( CLSID_LEADRasterVariant,
               NULL,
         CLSCTX_ALL,
         IID_ILEADRasterVariant,
         (void**)&pRasterVarX);

   CoCreateInstance( CLSID_LEADRasterVariant,
               NULL,
            CLSCTX_ALL,
            IID_ILEADRasterVariant,
            (void**)&pRasterVarY);

   switch (DispID)
   {
      case LEADRASTERANNOTATIONEVENTS_ANNDRAWN:
      {
         hAnnObject= OleVariant(Params.rgvarg[0]);
         pRasterAnn->AnnGetType(hAnnObject);
         nType= pRasterAnn->get_AnnType_();
           if (nType == ANN_OBJECT_POLYGON) //Is the object a polygon?
         {
            ShowMessage ("Object is a Polygon");

             pRasterAnn->AnnGetPointCount(hAnnObject); //get the number of points
            nPoints= pRasterAnn->AnnPointCount;
             pRasterAnn->AnnGetPointX((long)hAnnObject, pRasterVarX);    //get the X coordinates
             pRasterAnn-> AnnGetPointY ((long)hAnnObject, pRasterVarX);     //get the Y coordinates
             msgStr = "(";
            ShowMessage ("The polygon points " +IntToStr((int)nPoints)+ " are:");
             for (i=0; i<nPoints; i++)
            {
               x= pRasterVarX->get_LongItemValue(i - 1);
               y= pRasterVarY->get_LongItemValue(i - 1);
               msgStr= msgStr + "{" + FloatToStr(x) + "," + FloatToStr(y) + "}";
            }

            msgStr += ")";

             ShowMessage (msgStr);
         }
      }
      break;
   }
   if ( pRasterVarX )
      pRasterVarX->Release ( );

   if ( pRasterVarY )
      pRasterVarY->Release ( );
}