>I have had a bit of a go at using the API from Delphi, but just can't get
>things working. The problem seems to be what the hGrid relates to in
>Delphi. Can anybody provide a simple Delphi example that, for example,
>opens a grid and reads a value at x,y ?
>
>There have been a few questions regarding this on the list so I suspect I
>am not alone.
and
>I got the documentation for the grid engine from MapInfo (a file named
>grideng30.exe containing 2 word files). It did contain documentation for
the
>Grid API functions, but missed a description of the various C-structures
(or
>records in Pascal) used by the API.
>
>It it possible for you to publish the missing documentation for these
>C-structures, or - best of all - a simple C or Delphi (working) example
with
>source code.??
I don't have access to Delphi nor Pascal, but here is an example that
demonstrates using the GridEngine from MapBasic. This sample program opens
a grid file and retrieves a value from it. Give it a try.
'
*****************************************************************************
' Copyright (c) 2000, MAPINFO CORPORATION
' All rights reserved.
'
' $Workfile: GridInfo.mb $
' $Revision: 1.0 $
' $Author: DRESSEL $
' $Date: May 22 2000 16:14:56 $
'
' Module Description:
'
' MapBasic program to retrieve grid info.
'
' Revision History:
'
' Rev 1.0 May 22 2000 16:14:56 DRESSEL
'
*****************************************************************************
Include "MapBasic.def"
Include "Menu.def"
Include "Icons.def"
Declare Sub Main
Declare Sub GridInfoToolHandler
Declare Sub About
Declare Sub GoodBye
Define AppVersion 1.0
'Note: All MapBasic funtion variables are passed by reference unless
' explicitly defined to be passed directly with the 'ByVal' key word.
Declare Function GE_OpenGrid Lib "Migrid.dll" (
lpszFilename As String,
ByVal lCacheSize As Integer,
hGrid As Integer) As Logical
Declare Function GE_GetCoordSysInfo Lib "Migrid.dll" (
ByVal hGrid As Integer,
ptchCoordSys As String,
pdMinXVal As Float,
pdMinYVal As Float,
pdMaxXVal As Float,
pdMaxYVal As Float) As Logical
Declare Function GE_GetContinuousMinMax Lib "Migrid.dll" (
ByVal hGrid As Integer,
pdMinZVal As Float,
pdMaxZVal As Float) As Logical
Declare Function GE_GetDimensions Lib "Migrid.dll" (
ByVal hGrid As Integer,
plWidth As Integer,
plHeight As Integer) As Logical
Declare Function GE_StartRead Lib "Migrid.dll" (
ByVal hGrid As Integer) As Logical
Declare Function GE_GetContinuousValue Lib "Migrid.dll" (
ByVal hGrid As Integer,
ByVal lCol As Integer,
ByVal lRow As Integer,
pdValue As Float,
puchIsNull As SmallInt) As Logical
Declare Function GE_EndRead Lib "Migrid.dll" (
ByVal hGrid As Integer) As Logical
Declare Function GE_CloseGrid Lib "Migrid.dll" (
hGrid As Integer) As Logical
Global gsPath As String
Sub Main
OnError Goto HandleError
Create Menu "&Grid Info" As
"&About Grid Info..." Calling About,
"E&xit Grid Info" Calling Goodbye
Alter Menu "Tools" Add "&Grid Info" As "&Grid Info"
Alter ButtonPad "Tools"
Add
Separator
ToolButton
Icon MI_ICON_INFO
HelpMsg "Retrieve grid value"
Cursor MI_CURSOR_CROSSHAIR
DrawMode DM_CUSTOM_POINT
Calling GridInfoToolHandler
Show
Exit Sub
HandleError:
Note "Main: " + Error$()
Resume Next
End Sub
Sub GridInfoToolHandler
OnError Goto HandleError
Dim sCmd As String
Dim i As SmallInt
Dim lVerbose As Logical
Dim x, y As Float
Dim MapWindowID As Integer
Dim lReturn As Logical
Dim hGrid As Integer
Dim sPath As String
Dim ptchCoordSys As String
Dim pdMinXVal, pdMinYVal, pdMaxXVal, pdMaxYVal As Float
Dim pdMinZVal, pdMaxZVal As Float
Dim plWidth, plHeight As Integer
Dim lCol, lRow As Integer
Dim pdValue As Float
Dim puchIsNull As SmallInt
MapWindowID = FrontWindow()
If WindowInfo( MapWindowID, WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "Click in a map window."
Exit Sub
End If
For i = 1 To MapperInfo(MapWindowID, MAPPER_INFO_LAYERS)
If LayerInfo(MapWindowID, i, LAYER_INFO_TYPE) =
LAYER_INFO_TYPE_GRID Then
sPath = LayerInfo(MapWindowID, i, LAYER_INFO_PATH)
Exit For
End If
Next
sPath = Left$(sPath, Len(sPath)-3) + "MIG"
If sPath <> gsPath Then
gsPath = sPath
lVerbose = TRUE
Else
lVerbose = FALSE
End If
sCmd = "Set " + MapperInfo(MapWindowID,
MAPPER_INFO_COORDSYS_CLAUSE_WITH_BOUNDS)
Run Command sCmd
x = CommandInfo(CMD_INFO_X)
y = CommandInfo(CMD_INFO_Y)
Print "X = " + x + ", Y = " + y
lReturn = GE_OpenGrid(sPath, 1024, hGrid)
If lReturn Then
If lVerbose Then
Print " Opened " + sPath + " with handle " + hGrid
End If
If hGrid <> 0 Then
ptchCoordSys = Space$(255) 'Initialize to allocate actually memory.
lReturn = GE_GetCoordSysInfo(hGrid, ptchCoordSys, pdMinXVal,
pdMinYVal, pdMaxXVal, pdMaxYVal)
If lVerbose Then
Print " " + ptchCoordSys
Print " MinXVal = " + pdMinXVal + ", MinYVal = " + pdMinYVal +
", MaxXVal = " + pdMaxXVal + ", MaxYVal = " + pdMaxYVal
End If
lReturn = GE_GetContinuousMinMax(hGrid, pdMinZVal, pdMaxZVal)
If lVerbose Then
Print " MinZVal = " + pdMinZVal + ", MaxZVal = " + pdMaxZVal
End If
lReturn = GE_GetDimensions(hGrid, plWidth, plHeight)
If lVerbose Then
Print " Width = " + plWidth + ", Height = " + plHeight
End If
lReturn = GE_StartRead(hGrid)
If lReturn Then
lCol = (plWidth * (x - pdMinXVal) / (pdMaxXVal - pdMinXVal)) - .5
lRow = (plHeight -
plHeight * (y - pdMinYVal) / (pdMaxYVal - pdMinYVal)) - .5
lReturn = GE_GetContinuousValue(hGrid, lCol, lRow, pdValue,
puchIsNull)
If lCol < 0 Or lRow < 0 Or lCol >= plWidth Or lRow >= plHeight Then
If pdValue = 0 Then
Print " Value at col: " + (lCol+1) +
", row: " + (lRow+1) + " is undefined."
Else
Print " Value at col: " + (lCol+1) +
", row: " + (lRow+1) + " = " + pdValue +
", but should be undefined."
End If
Else
If puchIsNull Then
Print " Value at col: " + (lCol+1) +
", row: " + (lRow+1) + " is NULL."
Else
Print " Value at col: " + (lCol+1) +
", row: " + (lRow+1) + " = " + pdValue
End If
End If
lReturn = GE_EndRead(hGrid)
Else
Print " StartRead(" + hGrid + ") failed"
End If
lReturn = GE_CloseGrid(hGrid)
Else
Print "Open " + sPath + " failed: grid handle = 0"
End If
Else
Print "Open " + sPath + " failed"
End If
Exit Sub
HandleError:
Note "RotateSymbols: " + Error$()
Resume Next
End Sub
Sub About
OnError Goto HandleError
Dialog
Title "About Grid Info (Version " + Str$(AppVersion) + ")"
Width 160
Control StaticText
Title "Open grid and retrieve value at mouse click."
Position 10, 10
Control StaticText
Title "Select 'i' tool from 'Tools' button pad and"
Position 10, 18
Control StaticText
Title "click on grid in a map window."
Position 10, 26
Control OKButton
Title "&OK"
Exit Sub
HandleError:
Note "About: " + Error$()
Resume Next
End Sub
Sub GoodBye
OnError Goto HandleError
End Program
Exit Sub
HandleError:
Note "GoodBye: " + Error$()
Resume Next
End Sub
' End of File
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]