【以下如未特殊说明,Delphi版本均为D7】欢迎大家补充
<不知道还有多少兄弟还坚持Delphi,希望大家不要放弃~>
1.导入类库不正确。
典型症状为IFeatureLayer.Get_FeatureClass后要么不正确,要么为nil。
版本:D7
解决办法:安装D7补丁1。推荐地址:http://www.2ccc.com/article.asp?articleid=1202
2.Delphi下调用接口方法,不能按照属性来调用,而且,不能安全调用,经常需要OleCheck,代码写的很繁琐。
典型症状如下:
var
pLyr:IFeatureLayer;
pVisible:WordBool;
begin
OleCheck(pLyr.Get_Visible(pVisible));
而在dotnet下调用的代码则是:
ESRI.ArcGIS.Carto.IFeatureLayer pLyr = null;
bool pVisible = pLyr.Visible;
解决办法:
在导入类型库之前,进行Delphi环境设置
Tools | Environment Options | Type Library
在SafeCall function mapping选项下,勾选 "All v-table interfaces"
参考文章:http://forums.esri.com/Thread.asp?c=93&f=1170&t=165456&mc=6
从此,我们这样编写代码
var
pLyr:IFeatureLayer;
pVisible:WordBool;
begin
pVisible:=pLyr.Visible;
【如果目前已经有项目存在,建议不宜进行此项改动,因为涉及到的地方很多,修改的工作量很大】
3.在界面上的MapControl之类的控件,他们事件方法中带有OleVariant就会报错
典型症状和解决办法:参考http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35420&page=1#pid447173
另外啰嗦一句:如果遇到不能确定类型的变量,可以将其修改为IUnknown,比如
TMapControlOnViewRefreshed = procedure(ASender: TObject; ActiveView: IActiveView;
viewDrawPhase: Integer;
layerOrElement: IUnknown;
envelope: IEnvelope) of object;
其他的控件如果遇到类似问题,可以做同样修改。
4.浮点溢出
典型症状和解决办法
http://www.geo-spatial.net/csk/arcgis9/317.aspx
5.工具条自定义
典型症状:看到ESRI自带的例子D:\Program Files\ArcGIS\DeveloperKit\SamplesNET\Engine\ToolbarControlCustomization
哪怕是在VB下都可以很轻松的实现,但在Delphi下却为何如此困难?莫非Delphi是后娘养的?
其实不然,具体实现如下

Code
1
{******************************************************************************}
2
{ @UnitName : unt_CustomDLG }
3
{ @Project : Project1 }
4
{ @Copyright : }
5
{ @Author : Feedback }
6
{ @CreateDate : 2009-03-10 20:55:29 }
7
{ @LastUpdate : 2009-03-10 20:55:29 by Feedback }
8
{ @Description : esri工具条自定义 }
9
{ @Comment : }
10
{ @History : }
11
{******************************************************************************}
12
unit unt_CustomDLG;
13
14
interface
15
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
16
Dialogs, esriControls_TLB, OleCtrls, Menus, esriDisplay_tlb;
17
18
type
19
TCustomizeDialog = class(TInterfacedObject, ICustomizeDialogEvents)
20
private
21
m_CustomizeDialog: ICustomizeDialog;
22
FList: TList;
23
FEventsID: LongWord;
24
FhWndParent: THandle;
25
FPopupMenu: TPopupMenu;
26
function _AddRef: Integer; stdcall;
27
function _Release: Integer; stdcall;
28
public
29
function QueryInterface(const IID: TGUID; out Obj): HResult; virtual;
30
stdcall;
31
public
32
//接口方法
33
procedure OnStartDialog; safecall;
34
procedure OnCloseDialog; safecall;
35
//外部调用
36
procedure ShowDLG;
37
destructor Destroy; override;
38
constructor Create(EsriToolBarList: TList; hWndParent: THandle);
39
end;
40
41
implementation
42
43
uses ComObj;
44
45
{ TCustomizeDialog }
46
47
procedure TCustomizeDialog.OnCloseDialog; safecall;
48
var
49
I: Integer;
50
pToolbarControl: TToolbarControl;
51
begin
52
for I := 0 to FList.Count - 1 do
53
begin
54
pToolbarControl := TToolbarControl(FList.Items[I]);
55
pToolbarControl.Customize := False;
56
pToolbarControl.PopupMenu := FPopupMenu;
57
end;
58
59
end;
60
61
procedure TCustomizeDialog.OnStartDialog; safecall;
62
var
63
I: Integer;
64
pToolbarControl: TToolbarControl;
65
begin
66
for I := 0 to FList.Count - 1 do
67
begin
68
pToolbarControl := TToolbarControl(FList.Items[I]);
69
FPopupMenu := pToolbarControl.PopupMenu;
70
pToolbarControl.PopupMenu := nil;
71
pToolbarControl.Customize := True;
72
end;
73
end;
74
75
function TCustomizeDialog._AddRef: Integer;
76
begin
77
Result := 1;
78
end;
79
80
function TCustomizeDialog._Release: Integer;
81
begin
82
Result := 1;
83
end;
84
85
function TCustomizeDialog.QueryInterface(const IID: TGUID;
86
out Obj): HResult;
87
const
88
E_NOINTERFACE = HResult($80004002);
89
begin
90
if GetInterface(IID, Obj) then
91
Result := 0
92
else
93
Result := E_NOINTERFACE;
94
95
end;
96
97
constructor TCustomizeDialog.Create(EsriToolBarList: TList; hWndParent:
98
THandle);
99
var
100
pConnPnt: IConnectionPoint;
101
II: TGUID;
102
FEventsID2: LongWord;
103
begin
104
FList := EsriToolBarList;
105
FhWndParent := hWndParent;
106
m_CustomizeDialog := CoCustomizeDialog.Create as ICustomizeDialog;
107
II := IID_ICustomizeDialogEvents;
108
(m_CustomizeDialog as IConnectionPointContainer).FindConnectionPoint(II,
109
pConnPnt);
110
//if Succeeded((m_CustomizeDialog as IConnectionPointContainer).FindConnectionPoint(II,pConnPnt)) then
111
if (pConnPnt <> nil) then
112
pConnPnt.Advise(Self as IInterface, FEventsID);
113
end;
114
115
destructor TCustomizeDialog.Destroy;
116
var
117
II: TGUID;
118
pConnPnt: IConnectionPoint;
119
begin
120
if FEventsID > 0 then
121
begin
122
II := IID_ICustomizeDialogEvents;
123
// if Succeeded((m_CustomizeDialog as IConnectionPointContainer).FindConnectionPoint(II,pConnPnt)) then
124
(m_CustomizeDialog as IConnectionPointContainer).FindConnectionPoint(II,
125
pConnPnt);
126
if (pConnPnt <> nil) then
127
pConnPnt.UnAdvise(FEventsID);
128
FEventsID := 0;
129
end;
130
m_CustomizeDialog := nil;
131
inherited;
132
end;
133
134
procedure TCustomizeDialog.ShowDLG;
135
begin
136
m_CustomizeDialog.StartDialog(FhWndParent);
137
end;
138
139
end.