| 内容摘要 |
通常在使用vb编写 ArcObject 代码的时用到IPointCollection.AddPoint(),ISegmentCollection.AddSegment()等方法时会 有两个可选参数 before after 这些参数描述了 几何对象加入到集合中的位置。在vb中这些参数
可选填, 但在 .net 和 delphi 中并未对这些方法进行参数可选的重载 那么如何正确使用呢请参照下面的代码 |
| 过程描述 |
/*
*.net 的空参数使用 C#
*/
IPoint p = new PointClass();
p.PutCoords(0,0) ;
object ep = System.Reflection.Missing.Value;
IPointCollection pts = new PolylineClass();
pts.AddPoint(p,ref ep , ref ep) ;
...
object aft = (object)index;
pts.AddPoint(pPoint,ref missing, ref aft);
...
//
//delphi下的用法
//
首先添加引用
implementation
uses
OleCtrls, //或 Variants
//若选填参数不填则使用其包中空参数 emptyparam
pts.AddPoint(p,emptyparam,emptyparam);
//
//注 emptyparam 可能会因程序的内存泄漏而导致其中有值在代码编写时注意对象 和指针的释放
//也可以仿照Variants包中初始话emptyparam的函数自己编写产生空变量的函数 SetEmpty()所用到的函数
//可以从Variants中copy在此就不列出详细代码了
//
procedure SetEmpty(var V:OleVariant);
begin
If VarIsEmptyParam(v) then exit;
SetClearVarToEmptyParam(TVarData(v));
end;
////调用时
SetEmpty(emptyparam);
pts.AddPoint(p,emptyparam,emptyparam);
/// 这样可确保emptyparam 确实为空 |
(本文已被浏览 次) | | |