MSXML上的过程参数错误 [英] Procedure Parameter Error on MSXML
问题描述
下面是我正在运行的代码,但出现错误:
Below is the code that I am running and I am getting an error:
我已经检查了 uses
,就可以了.
I already checked the uses
and it's fine.
我认为我的 AddSimpleElement()
过程的参数有问题.
I think it is a problem with the parameter of my AddSimpleElement()
procedure.
unit Unit9;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleServer,
QBXMLRP2Lib_TLB, MSXML, XMLDoc;
type
TForm9 = class(TForm)
btnSubscribe: TButton;
btnUnsubscribe: TButton;
rp21: TRequestProcessor2;
private
{ Private declarations }
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
public
{ Public declarations }
end;
var
Form9: TForm9;
implementation
{$R *.dfm}
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
var
newElem : IXMLDOMElement;
begin
newElem := doc.createElement(name);
newElem.text := value;
parent.appendChild(newElem);
end;
end.
推荐答案
下面是我正在运行的代码
Below is the code that I am running
我认为运行"不是正确的词,因为您显示的代码甚至无法编译,更不用说运行了.
I think "running" is not the right word, because the code you have shown will not even compile, let alone run.
在代码的这一部分
type
TForm9 = class(TForm)
[...]
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
[...]
您将 AddSimpleElement
声明为TForm9类的方法,但是在此代码中
you declare AddSimpleElement
as a method of your TForm9 class, but in this code
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
var
newElem : IXMLDOMElement;
begin
newElem := doc.createElement(name);
newElem.text := value;
parent.appendChild(newElem);
end
与您所想的相反,您没有定义TForm9的 AddSimpleElement
的实现.而是声明一个独立的过程AddSimpleElement,该过程与TForm9完全没有关系.将您的代码更改为
you don't define the implementation of TForm9's AddSimpleElement
, contrary to what you might be thinking. Instead you declare a stand-alone procedure AddSimpleElement which has no relation to TForm9 at all. Change your code to
procedure TForm9.AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
var
newElem : IXMLDOMElement;
begin
[...]
,您将提高代码编译的机会.当然,仍然可能还有其他问题.
and you will improve the chances of your code compiling. There may still be other problems, of course.
顺便说一句,这是一种容易犯的错误,尤其是在漫长的一天结束时.您可以通过使用IDE的类完成"帮助来避免这种情况.键入后
Btw, this is the sort of mistake it is easy to make, especially at the end of a long day. You could have avoided it by using the IDE's "Class completion" assistance. After you type
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
在TForm9的类型声明中,如果按 Ctrl-Shift-C ,则IDE将生成该方法的(空)实现并将光标移至该方法.
in TForm9's type declaration, if you press Ctrl-Shift-C, then the IDE will generate the (empty) implementation of the method and move the cursor to it.
顺便说一句,如果您不介意我说的话,您q的愚蠢部分包括完全无用的屏幕截图,但您的q中并未提及尝试时编译器将产生的错误消息的确切文本来编译您的代码.在这种情况下,一目了然的代码错误是显而易见的,但是在这里寻求帮助时,您确实应该尽力提供最佳信息.
Btw, if you don't mind me saying, the dumb part of your q was including the completely unhelpful screen-shot, but not mentioning in your q the exact text of the error message the compiler would have produced when you attempted to compile your code. In this case, it was obvious at a glance what one glaring error with your code is, but you really should try to provide the best information you can when asking for help here.
这篇关于MSXML上的过程参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!