E
emoth
Unregistered / Unconfirmed
GUEST, unregistred user!
兄弟我在用DELPHI通过Active访问CAD时出现以下问题:
[以下是 CAD 中 SelectionSet 对象的 SelectOnScreen 方法定义]
Signature
object.SelectOnScreen [FilterType][, FilterData]
Object
SelectionSet:The object or objects this method applies to.
FilterType
Integer; input-only; optional A DXF group code specifying the type of filter to use.
FilterData
Variant; input-only; optional The value to filter on.
Remarks
This method supports the filtering mechanism.
AutoCAD's default prompt for picking an object will be used automatically.
For more selection mode options, see the Select, SelectByPolygon, and SelectAtPoint methods.
[以下是该方法的 VBA 程序举例]
Sub Example_Select()
Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2")
mode = acSelectionSetFence
ReDim gpCode(0 To 1) As Integer
gpCode(0) = 8
gpCode(1) = 62
ReDim dataValue(0 To 1) As Variant
dataValue(0) = "0"
dataValue(1) = acWhite
Dim groupCode As Variant, dataCode As Variant
groupCode = gpCode
dataCode = dataValue
ssetObj.SelectOnScreen groupCode, dataCode
End Sub
我将上面例程用VB改写后能通过,且可以省略参数。但是用DELPHI改写后却不能通过,总是提示未知的
OLE错误?代码如下:
procedure Example_Select;
var
intFilterType:array of Integer;
varFilterData:array of Variant;
FilterType:Variant;
FilterData:Variant;
begin
try
cadapp:=GetActiveOleObject('AutoCAD.Application') as IAcadApplication;
AcadDocument1.ConnectTo(cadapp.ActiveDocument);
except
ShowMessage('Error! CAD NOT RUN !!');
exit;
end;
try
setlength(intFilterType,2);
setlength(varFilterData,2);
//以下为选择过滤器代码编号
intFilterType[0]:=8;
intFilterType[1]:=62;
//以下为对应的选择过滤器内容
varFilterData[0]:='0';
varFilterData[1]:=acWhite;
FilterType:=intFilterType;
FilterData:=varFilterData;
try
AcadDocument1.SelectionSets.Add('NewSelect');
★ AcadDocument1.SelectionSets.Item('NewSelect').SelectOnScreen(FilterType,FilterData);
finally
AcadDocument1.SelectionSets.Item('NewSelect').Delete;
end;
except
on E:Exception do
ShowMessage(E.Message);
end;
end;
程序执行到★句时就会出现OLE未知错误,我猜测是DELPHI在向OLE服务器传递FilterType,FilterData
参数时的数据类型有问题,根据《DELPHI 5 开发人员指南》中所述
“VarArrayRef()主要用来解决向OLE服务器传送Variant数组时要出现的问题。当向自动化服务器的
方法传送一个包含Variant数组的Variant变量时,问题就产生了,例如:
server.PassVariantArray(VA)
这里传送的不是一个variant数组,而是一个包含了variant数组的variant变量,这是有明显区别的。
如果自动化服务器希望接收一个variant数组而不是指向它的一个引用,如果用上面的语法来调用自动
化的方法,就会产生一个错误。在这种情况下就要用VarArrayRef(),示例如下:
server.PassVariantArray(VarArrayRef(VA))”
我在程序中添加了VarArrayRef()函数还是无法正常运行(同样的错误),请教各位这是为何!!
附 Delphi 中CAD接入模块中的该方法声明
procedure SelectOnScreen(FilterType: OleVariant; FilterData: OleVariant); safecall;
另外,我在DELPHI中还不能象VB那样可以省略参数,必须指定FilterType,FilterData,真是气人。
[以下是 CAD 中 SelectionSet 对象的 SelectOnScreen 方法定义]
Signature
object.SelectOnScreen [FilterType][, FilterData]
Object
SelectionSet:The object or objects this method applies to.
FilterType
Integer; input-only; optional A DXF group code specifying the type of filter to use.
FilterData
Variant; input-only; optional The value to filter on.
Remarks
This method supports the filtering mechanism.
AutoCAD's default prompt for picking an object will be used automatically.
For more selection mode options, see the Select, SelectByPolygon, and SelectAtPoint methods.
[以下是该方法的 VBA 程序举例]
Sub Example_Select()
Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2")
mode = acSelectionSetFence
ReDim gpCode(0 To 1) As Integer
gpCode(0) = 8
gpCode(1) = 62
ReDim dataValue(0 To 1) As Variant
dataValue(0) = "0"
dataValue(1) = acWhite
Dim groupCode As Variant, dataCode As Variant
groupCode = gpCode
dataCode = dataValue
ssetObj.SelectOnScreen groupCode, dataCode
End Sub
我将上面例程用VB改写后能通过,且可以省略参数。但是用DELPHI改写后却不能通过,总是提示未知的
OLE错误?代码如下:
procedure Example_Select;
var
intFilterType:array of Integer;
varFilterData:array of Variant;
FilterType:Variant;
FilterData:Variant;
begin
try
cadapp:=GetActiveOleObject('AutoCAD.Application') as IAcadApplication;
AcadDocument1.ConnectTo(cadapp.ActiveDocument);
except
ShowMessage('Error! CAD NOT RUN !!');
exit;
end;
try
setlength(intFilterType,2);
setlength(varFilterData,2);
//以下为选择过滤器代码编号
intFilterType[0]:=8;
intFilterType[1]:=62;
//以下为对应的选择过滤器内容
varFilterData[0]:='0';
varFilterData[1]:=acWhite;
FilterType:=intFilterType;
FilterData:=varFilterData;
try
AcadDocument1.SelectionSets.Add('NewSelect');
★ AcadDocument1.SelectionSets.Item('NewSelect').SelectOnScreen(FilterType,FilterData);
finally
AcadDocument1.SelectionSets.Item('NewSelect').Delete;
end;
except
on E:Exception do
ShowMessage(E.Message);
end;
end;
程序执行到★句时就会出现OLE未知错误,我猜测是DELPHI在向OLE服务器传递FilterType,FilterData
参数时的数据类型有问题,根据《DELPHI 5 开发人员指南》中所述
“VarArrayRef()主要用来解决向OLE服务器传送Variant数组时要出现的问题。当向自动化服务器的
方法传送一个包含Variant数组的Variant变量时,问题就产生了,例如:
server.PassVariantArray(VA)
这里传送的不是一个variant数组,而是一个包含了variant数组的variant变量,这是有明显区别的。
如果自动化服务器希望接收一个variant数组而不是指向它的一个引用,如果用上面的语法来调用自动
化的方法,就会产生一个错误。在这种情况下就要用VarArrayRef(),示例如下:
server.PassVariantArray(VarArrayRef(VA))”
我在程序中添加了VarArrayRef()函数还是无法正常运行(同样的错误),请教各位这是为何!!
附 Delphi 中CAD接入模块中的该方法声明
procedure SelectOnScreen(FilterType: OleVariant; FilterData: OleVariant); safecall;
另外,我在DELPHI中还不能象VB那样可以省略参数,必须指定FilterType,FilterData,真是气人。