Using the Magnifying Glass (Delphi 6.0)

Take the following steps to enable the generation of the MagGlassExt event and updating the zoomed image using the Internet COM object toolkit.

1.

Start Delphi.

2.

If you didn’t install LEAD Raster View Control, install it as follows:

 

On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD Raster View Control (14.5). Press install.

3.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Internet Object Library (14.5).

4.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO Object Library (14.5).

5.

Select the LEAD RasterView control and add the control to your main form. Size and position the control, as you want it to appear at run time.

6.

From the ActiveX controls tab, add the LEAD Raster Inet, and LEAD Raster IO controls to your form.

7.

Add seven command buttons to your main form and name them as follows:

 

Name

Caption

 

btnStartUpServer

Start Up Server.

 

btnShutDownServer

Shut Server Down.

 

btnConnectToRemoteServer

Connect To Remote Server.

 

btnDisconnectFromRemoteServer

Disconnect From Remote Server.

 

btnLoadRemoteImage

Load Remote Image.

 

btnStartMagnifyingGlass

Start Magnifying Glass.

 

btnStopMagnifyingGlass

Stop Magnifying Glass.

8.

Add an Edit box to your main form and name it as follows:

 

Name

 

 

edtRemoteComputer.

 

9.

Set the Text property to the name of the computer you will use as a server.

10.

Declare the following in the Private section of Unit1.

    hServer: SmallInt; //handle to server
    gnCommandID: Longint;
    bMagGlass: Boolean;

11.

Handle the Form1 OnCreate event, and code the FormCreate procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.FormCreate(Sender: TObject); 
begin

   // Initialize some variables
   hServer := 0; 
   gnCommandID := 0; 
   bMagGlass := False; 

   // Set defaults for displaying the image. 
   // These are all persistent properties that can be set in the properties box. 
   LEADRasterView1.Appearance := RASTERVIEW_APPEARANCE_FLAT; 
   LEADRasterView1.BorderStyle := 1; 
   LEADRasterView1.BackColor := RGB(255, 255, 125); 
   LEADRasterView1.PaintDither := PAINTDITHER_DIFFUSION; 
   LEADRasterView1.PaintPalette := PAINTPALETTE_AUTO; 
   LEADRasterView1.AutoRepaint := True; 
   LEADRasterView1.AutoSize := False; 
   LEADRasterView1.AutoSetRects := True; 
   LEADRasterView1.PaintSizeMode := PAINTSIZEMODE_FIT; 

   // Unlock support for the Inet object. 


   // Stop generation of runtime exceptions for LEAD RasterView Control, LEAD
   // LEAD Raster IO Object Library and LEAD Raster Internet Object Library. 
   LEADRasterView1.EnableMethodErrors := False; 
   LEADRasterIO1.EnableMethodErrors := False; 
   LEADRasterInet1.EnableMethodErrors := 0; 
end; 

12.

Handle the Form1 OnDestroy event, and code the FormDestroy procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

procedure TForm1.FormDestroy(Sender: TObject); 
var
   i: Integer; 
begin
   //Disconnect all connections
   for i := 0 to LEADRasterInet1.ConnectListNum - 1 do
      LEADRasterInet1.InetDisconnect (LEADRasterInet1.ConnectList [i]); 

   if (bMagGlass) then
      LEADRasterView1.StopMagGlass (  ); 
end; 

13.

Code the btnStartUpServer button's click procedure as follows:

procedure TForm1.btnStartUpServerClick(Sender: TObject); 
var
   nRet: Integer; 
begin
   //Initialize server on port 1000
   nRet:= LEADRasterINet1.InetServerInit (1000); 
   hServer:= LEADRasterINet1.InetServerHandle;
   if (nRet <> 0) then
      ShowMessage ('Error Initializing server: ' + IntToStr(nRet)); 
end; 

14.

Code the btnShutDownServer button's click procedure as follows:

procedure TForm1.btnShutDownServerClick(Sender: TObject); 
var
   nRet: Integer; 
begin
   if (hServer <> 0) then
   begin
      nRet:= LEADRasterInet1.InetServerClose (hServer); 

      if (nRet <> 0) then
         ShowMessage ('Error Shutting Down server: ' + IntToStr(nRet)) 
      else
         hServer:= 0; 
   end; 
end; 

15.

Code the btnConnectToRemoteServer button's click procedure as follows:

procedure TForm1.btnConnectToRemoteServerClick(Sender: TObject); 
var
   nRet: Integer; 
begin
   //Connect to remote computer on port 1000
   nRet:= LEADRasterInet1.InetConnect (edtRemoteComputer.Text, 1000); 

   if (nRet <> 0) then
      ShowMessage ('Error connecting to ' + edtRemoteComputer.Text + ': ' + IntToStr(nRet)); 
end; 

16.

Code the btnDisconnectFromRemoteServer button's click procedure as follows:

procedure TForm1.btnDisconnectFromRemoteServerClick(Sender: TObject); 
var
   nRet: Integer; 
begin
   { We are assuming only one connection in this example. 
    Therefore, the handle to the remote computer will be
    in the first position in the SendList}
   nRet:= LEADRasterInet1.InetDisconnect (LEADRasterInet1.SendList [0]); 
   if (nRet <> 0) then
      ShowMessage ('Error disconnecting from remote: ' + IntToStr(nRet)); 
end; 

17.

Code the btnLoadRemoteImage button's click procedure as follows:

procedure TForm1.btnLoadRemoteImageClick(Sender: TObject); 
var
   nRet: Integer; 
begin
   nRet:= LEADRasterInet1.InetSendLoadCmd (999, 'v:\images\Eagle.cmp', 0, 1); 

   if ((nRet <> 0) And (nRet <> ERROR_DATA_QUEUED)) then
        ShowMessage ('ERROR ' + IntToStr(nRet) + ' calling InetSendLoadCmd.'); 
end; 

18.

Code the btnStartMagnifyingGlass button's click procedure as follows:

procedure TForm1.btnStartMagnifyingGlassClick(Sender: TObject); 
var
   nRet: Integer; 
begin

   if ((LEADRasterView1.Raster.Bitmap <> 0) And (hServer = 0)) then
   begin
        //Enable MagGlassExt event. 
      if LEADRasterView1.EnableMagGlassEvent = False Then
         LEADRasterView1.EnableMagGlassEvent:= True; 

      LEADRasterView1.RgnFrameType:= 0; 

      //Start the Magnifying Glass
      nRet:= LEADRasterView1.StartMagGlass (100, 100, 400, RGB(255, 0, 0), RGB(128, 128, 128), True, 1, False, CROSSHAIR_FINE, True, True); 

      if (nRet = 0) then
         bMagGlass:= True; 
   end; 
end; 

19.

Code the btnStopMagnifyingGlass button's click procedure as follows:

procedure TForm1.btnStopMagnifyingGlassClick(Sender: TObject); 
var
   nRet: Integer; 
begin
   if ((LEADRasterView1.Raster.Bitmap <> 0) And (hServer = 0)) then
   begin
      nRet:= LEADRasterView1.StopMagGlass ( ); 

      if (nRet = 0) then
         bMagGlass:= False
   end; 
end; 

20.

Handle the LEADRasterInet1 OnInetAccept event, and code LEADRasterInet1InetAccept as follows:

procedure TForm1.LEADRasterInet1InetAccept (Sender: TObject; 
  iServer: Smallint); 
var
   nRet: Integer; 
   iComputer: SmallInt; 
   szHostName: WideString; 
begin
   nRet:= LEADRasterInet1.InetAcceptConnect (hServer); 
   iComputer:= LEADRasterInet1.InetConnectedComputer;
   if (nRet <> 0) then
   begin
      ShowMessage ('Error accepting connection: ' + IntToStr(nRet)); 
      Exit; 
   end; 

   LEADRasterInet1.InetGetHostName (iComputer, HOST_NAME_DESCRP);

   szHostName:= LEADRasterInet1.InetHostName;
   //Add to our list
   LEADRasterInet1.SendList [LEADRasterInet1.SendListNum]:= iComputer; 
   ShowMessage ('Connection accepted from: ' + szHostName); 
end; 

21.

Handle the LEADRasterInet1 OnInetConnected event, and code LEADRasterInet1InetConnected as follows:

procedure TForm1.LEADRasterInet1InetConnected (Sender: TObject; 
  iComputer: Smallint); 
var
   szHostName: WideString; 
begin
   //Get remote host name
   LEADRasterInet1.InetGetHostName (iComputer, HOST_NAME_DESCRP); 
szHostName:= LEADRasterInet1.InetHostName;
   //Add this connection to our SendList
   LEADRasterInet1.SendList [LEADRasterInet1.SendListNum]:= iComputer; 
   ShowMessage ('Successfully connected to remote computer: ' + szHostName ); 
end; 

22.

Handle the LEADRasterInet1 OnInetDisconnected event, and code LEADRasterInet1InetDisconnected as follows:

procedure TForm1.LEADRasterInet1InetDisconnected (Sender: Object;
  iComputer: Smallint); 
begin
   if (hServer = 0) then
      ShowMessage ('Disconnect from remote server') 
   else
      ShowMessage ('Connection to remote computer closed'); 
end; 

23.

Handle the LEADRasterInet1 OnInetReceiveCmd event, and code LEADRasterInet1InetReceiveCmd as follows:

procedure TForm1.LEADRasterInet1InetReceiveCmd(ASender: TObject; iComputer,
  InetCommand: Smallint; nCommandID: Integer; nError: Smallint;
  const Params: ILEADRasterInetPacket; nExtraDataSize: Integer;
  const pExtraData: ILEADRasterVariant);
var
   nStatus: SmallInt;
   vColorBuffer: LEADRasterVariant;

begin
   nStatus:= ERROR_FEATURE_NOT_SUPPORTED;
vColorBuffer:= coLEADRasterVariant.Create();
   if (nError <> 0) then
      nStatus:= ERROR_TRANSFER_ABORTED
   else
   begin
      Case (InetCommand) of
         INETCMD_LOAD:
         begin
            //check the validity of the parameters
            if ((Params.ParamCount = 4) And
                (Params.ParamType[0] = PARAM_TYPE_STRING) And
                (Params.ParamType[1] = PARAM_TYPE_INT32) And
                (Params.ParamType[2] = PARAM_TYPE_INT32) And
                (Params.ParamType[3] = PARAM_TYPE_UINT32)) then
            begin

               nStatus:= LEADRasterIO1.Load (LEADRasterView1.Raster,
                        Params.ParamValue[0].StringValue,
                                             Params.ParamValue[1].LongValue,
                                             1,
                                             1);

               if (nStatus <> 0) then
                  ShowMessage ('Load Bitmap failed with error code: ' + IntToStr(nStatus))
               else
               begin
                  nStatus:= LEADRasterInet1.InetSendBitmap (LEADRasterView1.Raster,
                              FILE_CMP,
                                                            0,
                                                            TOleEnum(QFACTOR_PQ2));

                  if (nStatus <> 0) then
                     ShowMessage ('SendBitmap failed with error code: ' + IntToStr(nStatus));
               end; 

            end
            else
               nStatus:= ERROR_INV_PARAMETER;    //Invalid parameters

            LEADRasterInet1.InetSendLoadRsp (nCommandID, 0, 0, pExtraData, nStatus);
            Exit; 
         end; 

         INETCMD_GET_MAGGLASS_DATA: 
         begin
            //check the validity of the parameters
            if ((Params.ParamCount = 5) And (Params.ParamType[0] = PARAM_TYPE_UINT32) 
               And (Params.ParamType[1] = PARAM_TYPE_UINT32) And (Params.ParamType[2] = PARAM_TYPE_USTRING) 
               And (Params.ParamType[3] = PARAM_TYPE_INT32) And (Params.ParamType[4] = PARAM_TYPE_INT32)) Then
            begin
               if LEADRasterView1.Raster.Bitmap <> 0 Then
               begin
                  nStatus:= LEADRasterInet1.InetGetMagGlassData (LEADRasterView1.Raster,
                              vColorBuffer,
                                                                  Params.ParamValue[2],
                                                                  Params.ParamValue[3].LongValue,
                                                                  Params.ParamValue[4].LongValue);

                  if (nStatus <> 0) then
                      ShowMessage ('InetGetMagGlassData failed with error code: ' + IntToStr(nStatus)) 
               end
               else
                  nStatus:= ERROR_INV_PARAMETER   //Invalid parameter
            end
            else
              nStatus:= ERROR_INV_PARAMETER;    //Invalid parameters
            LEADRasterInet1.InetSendGetMagGlassDataRsp ( nCommandID,
                           vColorBuffer,
                                                         Params.ParamValue[2],
                                                         Params.ParamValue[3].LongValue,
                                                         Params.ParamValue[4].LongValue,
                                                         0,
                                                         pExtraData,
                                                         nStatus);
            Exit;
         end;
        end;
   end;
   LEADRasterInet1.InetSendRsp (InetCommand, nCommandID, Nil, 0, pExtraData, nStatus);
end; 

24.

Handle the LEADRasterInet1 OnInetReceiveRsp event, and code LEADRasterInet1InetReceiveRsp as follows:

procedure TForm1.LEADRasterInet1InetReceiveRsp (Sender: TObject; iComputer, 
  InetCommand: Smallint; nCommandID: Integer; nError, nStatus: Smallint; 
  var Params: OleVariant; nExtraDataSize: Integer; ExtraData: OleVariant); 
var
   nRet: Integer; 
begin
   if (nError <> 0) then
      Exit; 

   Case (InetCommand) of
      INETCMD_LOAD: 
      begin
         if (nStatus <> 0) then
            ShowMessage ('Load failed with error code: ' + IntToStr(nStatus)); 
      end; 

      INETCMD_GET_MAGGLASS_DATA: 
      begin
         if (nStatus = 0) then
         begin
            if ((Params.ParamCount = 6) And (Params.ParamType[0] = PARAM_TYPE_UINT32) 
               And (Params.ParamType[1] = PARAM_TYPE_USTRING) And (Params.ParamType[2] = PARAM_TYPE_UINT32) 
               And (Params.ParamType[3] = PARAM_TYPE_USTRING) And (Params.ParamType[4] = PARAM_TYPE_INT32)) 
               And (Params.ParamType[5] = PARAM_TYPE_INT32) then
               begin
                  nRet:= LEADRasterView1.UpdateMagGlass(Params.ParamValue[1], Params.ParamValue[3], Params.ParamValue[4], Params.ParamValue[5], True); 

                  if (nRet <> 0) then
                     ShowMessage ('UpdateMagGlass failed with error code: ' + IntToStr(nRet)) 
               end
               else
                  ShowMessage ('Invalid parameter passed to INETCMD_GET_MAGGLASS_DATA response'); 
         end
         else
            ShowMessage ('Get MagGlass Data from server with error code ' + IntToStr(nStatus)); 
      end; 
   end; 
end; 
 

25.

Code the LEADRasterView1’s OnMagGlassExt event as follows:

procedure TForm1.LEADRasterView1MagGlassExt(Sender: TObject; 
  nMaskPlaneStart, nMaskPlaneEnd: Integer; const pvMaskPlane: ILEADRasterVariant); 
var
   nRet: Integer; 
begin

   gnCommandID:= gnCommandID + 1; 

   nRet:= LEADRasterInet1.InetSendGetMagGlassDataCmd (gnCommandID, 0, pMaskPlane, nMaskPlaneStart, nMaskPlaneEnd); 

   if ((nRet <> 0) And (nRet <> ERROR_DATA_QUEUED)) then
      ShowMessage ('ERROR ' + IntToStr(nRet) + ' calling InetSendGetMagGlassDataCmd.'); 
end; 

26.

At the beginning of the Unit1 file, add LTRASTERLib_TLB, LTDllDef, to the Uses section.

27.

Run the exe file two times to execute two applications.

28.

In the first application press the Start Up Server button.

29.

In the second application fill the edit box with the IP Address of the Remote computer on which you ran the first application as Server and then press the Connect To Remote Server button to connect to the specified address.

30.

After that press the Load Remote Image button of application number two to load an image on the Server. Then press the Start Magnifying Glass button to start the Magnifying Glass with Internet support. Press the left mouse button and move over the image to see the zoomed area using the Magnifying Glass with Internet support.