【以下如未特殊說明,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 FilesArCGISDeveloperKitSamplesNETEngineToolbarControlCustomization
哪怕是在VB下都可以很輕松的實現,但在Delphi下卻為何如此困難?莫非Delphi是後娘養的?
其實不然,具體實現如下
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{******************************************************************************}
12unit unt_CustomDLG;
13
14interface
15uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
16 Dialogs, esriControls_TLB, OleCtrls, Menus, esriDisplay_tlb;
17
18type
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
41implementation
42
43uses ComObj;
44
45{ TCustomizeDialog }
46
47procedure TCustomizeDialog.OnCloseDialog; safecall;
48var
49 I: Integer;
50 pToolbarControl: TToolbarControl;
51begin
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
59end;
60
61procedure TCustomizeDialog.OnStartDialog; safecall;
62var
63 I: Integer;
64 pToolbarControl: TToolbarControl;
65begin
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;
73end;
74
75function TCustomizeDialog._AddRef: Integer;
76begin
77 Result := 1;
78end;
79
80function TCustomizeDialog._Release: Integer;
81begin
82 Result := 1;
83end;
84
85function TCustomizeDialog.QueryInterface(const IID: TGUID;
86 out Obj): HResult;
87const
88 E_NOINTERFACE = HResult($80004002);
89begin
90 if GetInterface(IID, Obj) then
91 Result := 0
92 else
93 Result := E_NOINTERFACE;
94
95end;
96
97constructor TCustomizeDialog.Create(EsriToolBarList: TList; hWndParent:
98 THandle);
99var
100 pConnPnt: IConnectionPoint;
101 II: TGUID;
102 FEventsID2: LongWord;
103begin
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);
113end;
114
115destructor TCustomizeDialog.Destroy;
116var
117 II: TGUID;
118 pConnPnt: IConnectionPoint;
119begin
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;
132end;
133
134procedure TCustomizeDialog.ShowDLG;
135begin
136 m_CustomizeDialog.StartDialog(FhWndParent);
137end;
138
139end.