xws001
路人甲
路人甲
  • 注册日期2004-07-10
  • 发帖数13
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1917回复:2

未将对象引用设置到对象的实例

楼主#
更多 发布于:2004-07-15 20:52
<P>在C#+AO.NET(ArcGis8.3)中</P>
<P>int numDesiredClasses=0;
IClassify pClassify ;
ITableHistogram pTableHistogram ;
IHistogram pHistogram ;
object dataFrequency ;
object dataValues ;
object Classes;
int ClassesCount ;
              .
              .
pClassify =new  EqualInterval() as IClassify;
pTableHistogram =new  TableHistogram() as ITableHistogram;
pHistogram = pTableHistogram as IHistogram;
pTableHistogram.Field=strPopField1;
pTableHistogram.Table=recs;
pHistogram.GetHistogram(out dataValues, out dataFrequency);
pClassify.SetHistogramData(dataValues, dataFrequency);
numDesiredClasses=5;</P>
<P>            //执行到下面语句时为什么会出错
pClassify.Classify(ref numDesiredClasses);
错误信息:未将对象引用设置到对象的实例。</P>
<P>请指教,谢谢。</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2004-07-15 21:57
<H4>Summary</H4><DIV>Instructions provided describe how to implement an event sink object for ArcObjects using ATL IDispEventSimpleImpl template interface with Microsoft Visual C++ 6.0.

Event sink is the process by which events raised in a COM object are handled by callback functions on a special interface of another object. Fundamentally, both Visual C++ and Visual Basic use event sinks to monitor COM object's state and respond to the predefined events generated by them. Both of the above programming environments have complete and practical events handling mechanisms for COM objects and especially for ActiveX controls. Custom implementations of event sink are occasionally required for a particular need.</DIV><H4>Procedure</H4><DIV><OL><LI>Create a new MFC AppWizard project called EventSink. At Step 1 of the wizard, select Dialog based as the application type, accept all the default settings of the remainder of the wizard and click on Finish to create the project. <LI>Right-click on the EventSink project in the project explorer and select New ATL Object… in the context menu to add ATL support to the MFC project. No COM objects or controls must be added to the project, only ATL support is required. <LI>Add an ESRI MapControl to the project main dialog box IDD_EVENTSINK_DIALOG. <LI>Add a new class named CMCEventSinkObj. In the header file of CMCEventSinkObj class, add the following at the top,

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>#include "resource.h"
#pragma warning(push)
#pragma warning(disable : 4146)
#pragma warning(disable : 4192)
#import "C:\Program Files\arcgis\arcexe83\bin\esriCore.olb" raw_interfaces_only, raw_native_types, named_guids, exclude("OLE_COLOR", "OLE_HANDLE")
#import "C:\Program Files\arcgis\arcexe83\bin\MapControl.ocx" no_namespace, named_guids
#pragma warning(pop)</PRE></DIV><DIV 500px?><img src="http://support.esri.com/common/style/graphics/icons/note.gif"> Import esriCore.olb before importing MapControl.ocx because MapControl.ocx relies on the types defined in the esriCore.olb.</DIV><LI>Derive the CMCEventSinkObj from IDispEventSimpleImpl<…> class template as following:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>class CMCEventSinkObj : public IDispEventSimpleImpl<IDC_MAPCONTROL1, CMCEventSinkObj, ;DIID_IMapControlEvents2>
</PRE></DIV>
IDC_ MAPCONTROL1 is the ID of the map control, CMCEventSinkObj is the name of this event sink class, and DIID_IMapControlEvents2 is the GUID of the map control’s event interface. In COM, events are actually outbound methods defined on a special interface. When events are fired, these outbound methods invoke the corresponding handlers defined in the event sink to process the events. So events in COM are nothing more than a group of methods in a special interface. <LI>Open the OLE/COM Object Viewer, or OLE View by name, to study the Map Control event interface. Select View TypeLib and open the Map Control (MapControl.ocx) located under C:\arcgis\arcexe83\bin\. Expand Dispinterface and locate IMapControlEvents2. Define a static object of type _ATL_FUNC_INFO about the event method to respond to. In this example, select to catch the onMouseDown event. In OLE View, OnMouseDown takes 6 parameters, 4 or type long and 2 of type double. So the declaration is the following:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>static _ATL_FUNC_INFO MCOnMouseDownInfo = {CC_STDCALL, VT_I4, 6, {VT_I4, VT_I4, VT_I4, VT_I4, VT_R8, VT_R8}};</PRE></DIV>
Refer to the MSDN for more information about _ATL_FUNC_INFO. <LI>Define a member variable and a class constructor as following in class CMCEventSinkObj:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>HWND m_hWndList;
CMCEventSinkObj(HWND hWnd = NULL) : m_hWndList(hWnd)
{
}
</PRE></DIV><LI>Define the event sink map as following in class CMCEventSinkObj:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>BEGIN_SINK_MAP(CMCEventSinkObj)
 SINK_ENTRY_INFO(IDC_MAPCONTROL1, DIID_IMapControlEvents2, 1, MCOnMouseDown, ;MCOnMouseDownInfo)
END_SINK_MAP()
</PRE></DIV>
Because the id of method onMouseDown in IMapControlEvents2 is 1, in decimal value, specify 1 as the entry id for this method. MCOnMouseDown is the event handler that would be invoked on this event. <LI>Define the MCOnMouseDown method as following in class CMCEventSinkObj:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>HRESULT __stdcall MCOnMouseDown(short iButton, short iShift, long iX, long iY, double dMapX, double dMapY)
{
 TCHAR buf[1024];
 sprintf(buf, "You clicked at point (%i, %i).", iX, iY);
 ::SendMessage(m_hWndList, LB_ADDSTRING,0, (LPARAM)buf);
 return S_OK;
}
</PRE></DIV>
This event handler obtains the point at which the user clicked the mouse on the map control and sends a message string 'You clicked at point (X, Y)' to a listbox in which this string will be displayed.

<DIV 500px?><img src="http://support.esri.com/common/style/graphics/icons/note.gif"> The parameter signature corresponds to the COM interface definition.</DIV><LI>The event sink object for the map control is finished. The following is the code to test this sink object. Add a listbox to the dialog and name it as IDC_LIST1. Uncheck Sort on the Style tab in the property page. <LI>Define a CMCEventSinkObj in CEventSinkDlg class:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>CMCEventSinkObj* m_pMCEventSink;</PRE></DIV><LI>In the CEventSinkDlg::OnInitDialog() method, add the following at the bottom:

<DIV whitesmoke? BACKGROUND-COLOR: courier; FONT-FAMILY: solid; 2px #cccccc BORDER-BOTTOM: 0.5em; PADDING-TOP: 500px; WIDTH: BORDER-LEFT: PADDING-BOTTOM: PADDING-LEFT: BORDER-TOP: PADDING-RIGHT:><PRE PADDING-TOP: PADDING-BOTTOM: PADDING-LEFT: 0px? 0px; MARGIN:>m_pMCEventSink = new CMCEventSinkObj((GetDlgItem(IDC_LIST1))->m_hWnd );
HRESULT hr = m_pMCEventSink->DispEventAdvise((GetDlgItem(IDC_MAPCONTROL1)->GetControlUnknown()));
</PRE></DIV>
Run the program. The listbox displays the message sent from the event sink object. </LI></OL></DIV><H4>Related Information</H4><DIV><UL><LI><a href="http://msdn.microsoft.com/" target="_blank" ><FONT color=#0a8161>Microsoft Developer Network</FONT></A></LI></UL></DIV>
举报 回复(0) 喜欢(0)     评分
xws001
路人甲
路人甲
  • 注册日期2004-07-10
  • 发帖数13
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-07-16 23:01
gis 的这些英文,没看懂,真的没看懂!<img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部