2011-09-20 12 views
2

contentmodel에서 partilces에 액세스 할 때 '매개 변수가 잘못되었습니다.'가 표시되지만 itemtype을 읽는 것이 좋습니다. 누군가 나에게 무엇을해야한다고 말할 수 있습니까? 미리 감사드립니다.delphi를 사용하여 msxml6에서 complextype의 입자에 액세스하는 방법?

//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; 

단부;

답변

2

문제는 귀하의 코드에 없습니다. 문제는 결함있는 Delphi 7 TLB 가져 오기 도구 때문입니다. 내가 델파이 2010에 복사 - 붙여 넣기하는 경우가 xs:schema 닫는 태그를 포함하는 것을 잊었다는 사실을 제외하고

, 당신의 예는 가 잘 작동합니다.

델파이 7로 돌아 가기. contentModel의 .particles 속성에 액세스하면 OLE 코드 $ 80004001이 반환됩니다.

생성 된 TLB.pas를 간략히 살펴보면 .TLB 파일을 가져올 때 Delphi 7이 엉망이되었음을 알 수 있습니다. contentModel은 을 상속하는 ISchemaModelGroup 유형입니다. 이제 정의를 살펴보십시오.

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 방법을 참조하십시오. 델파이 2010은 그것들을 생성하지 않으며, 처음에는 거기에 있어서는 안됩니다 (get_particles 호출의 메소드 오프셋이 모두 잘못되었습니다).

MSXML2_TLB에서 GhostMethod_XXX 메서드를 주석 처리하면 예제가 매력처럼 작동합니다.

그러나 심하게 들여온 TLB로 인해서 언제든지 얼굴에 날아갈 수 있습니다. Delphi 2010에서 가져온 버전을 대신 사용하는 것이 좋습니다 (MSXML2_TLB.zip). Delphi 7에서 잘 작동하므로 조언을 구합니다.

관련 문제