当访问contentmodel中的部分时,我得到了‘该参数不正确’,但读取itemtype是可以的。有人能告诉我该怎么做吗?提前谢谢。
//Book.xsd
<xs:schema xmlns="urn:bookstore-schema" targetNamespace="urn:bookstore-schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book" type="booktype" />
<xs:complexType name="booktype">
<xs:sequence>
<xs:element name="author" type="xs:string" />
<xs:element name="price" type="xs:decimal" />
<xs:element name="aaa" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="another" type="xs:string" />
procedure AccessSchema;
var oSchemaCache : XMLSchemaCache60;
oSchema : ISchema;
nsTarget : string;
kk : integer;
procedure AccessComplexType(oComplex : iSchemaItem);
var ISchComplex : ISchemaComplexType;
begin
ISchComplex := oComplex as ISchemaComplexType;
if (iSchComplex.contentType = SCHEMACONTENTTYPE_MIXED) or
(iSchComplex.contentType = SCHEMACONTENTTYPE_ELEMENTONLY) then
begin
if (iSchComplex.contentModel.ItemType = SOMITEM_CHOICE) or
(iSchComplex.contentModel.ItemType = SOMITEM_SEQUENCE) then
begin
if IschComplex.contentModel.particles.length > 0 then
//error : the parameter is incorrect
begin
{handling particles }
end;
end;
end;
end;
begin
oSchemaCache := coXMLSchemaCache60.Create;
nsTarget := 'urn:bookstore-schema';
oSchemaCache.add(nsTarget,'c:\book.xsd');
oSchema := oSchemaCache.getSchema(nsTarget);
for kk := 0 to pred( oschema.types.length) do
begin
if (oschema.types.item[kk].itemType = SOMITEM_COMPLEXTYPE ) then
AccessComplexType(oschema.types.item[kk]);
end;结束;
发布于 2011-09-20 18:00:04
问题不在你的代码中,问题出在有问题的Delphi7TLB导入器。
除了您忘记包含xs:schema结束标记之外,如果我将它复制粘贴到Delphi2010中,您的示例就可以正常工作。
回到Delphi7。访问contentModel的.particles属性将返回OLE代码$80004001。
快速浏览一下生成的TLB.pas就会发现,在导入.TLB文件时,Delphi7搞砸了。contentModel的类型为ISchemaModelGroup,它继承自ISchemaItem。现在来看一下它的定义:
ISchemaParticle = interface(ISchemaItem)
['{50EA08B5-DD1B-4664-9A50-C2F40F4BD79A}']
procedure GhostMethod_ISchemaParticle_0_1; safecall;
procedure GhostMethod_ISchemaParticle_4_2; safecall;
procedure GhostMethod_ISchemaParticle_8_3; safecall;
procedure GhostMethod_ISchemaParticle_12_4; safecall;
procedure GhostMethod_ISchemaParticle_16_5; safecall;
procedure GhostMethod_ISchemaParticle_20_6; safecall;
procedure GhostMethod_ISchemaParticle_24_7; safecall;
procedure GhostMethod_ISchemaParticle_28_8; safecall;
procedure GhostMethod_ISchemaParticle_32_9; safecall;
procedure GhostMethod_ISchemaParticle_36_10; safecall;
procedure GhostMethod_ISchemaParticle_40_11; safecall;
procedure GhostMethod_ISchemaParticle_44_12; safecall;
procedure GhostMethod_ISchemaParticle_48_13; safecall;
procedure GhostMethod_ISchemaParticle_52_14; safecall;
function Get_minOccurs: OleVariant; safecall;
function Get_maxOccurs: OleVariant; safecall;
property minOccurs: OleVariant read Get_minOccurs;
property maxOccurs: OleVariant read Get_maxOccurs;
end;看到所有这些ghost_xxx方法了吗?Delphi2010不会生成这些,它们本来就不应该存在(它们会导致get_particles调用的方法偏移量都是错误的)。
只需在MSXML2_TLB中注释这些GhostMethod_XXX方法,您的示例就会非常出色。
然而,你仍然被一个糟糕的导入的TLB卡住了,它可能在任何时候在你面前爆炸。我建议您使用Delphi2010导入版本来代替(MSXML2_TLB.zip),因为它在Delphi7上工作得很好。
https://stackoverflow.com/questions/7478974
复制相似问题