TXMLDocumentGetDocBinding (C++)

From Appmethod Code Examples
Jump to: navigation, search

Description

The following example uses the GetDocBinding function.

Class diagram

Code

// Custom interface
__interface INTERFACE_UUID("{49C50BE3-4084-4A66-B919-000984A657FB}") ISpec
	: public IInterface {
public:
	virtual String __fastcall GetSpecField() = 0;
};
typedef System::DelphiInterface<ISpec>_di_ISpec;

// Custom class
class TSpecXMLNode : public TXMLNode, public ISpec {
	INTFOBJECT_IMPL_IUNKNOWN(TXMLNode);

public:
	void __fastcall AfterConstruction() {
		printf("%ls AfterConstruction.\n", TSpecXMLNode::ClassName());
	}

	String __fastcall GetSpecField() {
		return "FieldValue";
	}
};

void Test_GetDocBinding() {
	const String tag = "TestElement";
	_di_IXMLDocument document;

	document = interface_cast<Xmlintf::IXMLDocument>(new TXMLDocument(NULL));
	document->Active = true;

	// Register implementation class.
	// Should create the document element.
	// Should display "TSpecXMLNode AfterConstruction".
	_di_IXMLNode node = document->GetDocBinding(tag, __classid(TSpecXMLNode));

	// _di_ISpec interface to document element
	_di_ISpec specNode;

	if (node->Supports(specNode)) {
		printf("SpecField=%ls\n", specNode->GetSpecField());
	}
	else {
		// Should not happen.
		printf("Interface unsupported.\n");
	}
}

Uses