MSXML 上的过程参数错误
Procedure Parameter Error on MSXML
下面是我 运行 的代码,但出现错误:
我已经检查过 uses
没问题。
我认为我的 AddSimpleElement()
程序的参数有问题。
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
我认为 "running" 不是正确的词,因为您显示的代码甚至无法编译,更不用说 运行.
在你的这部分代码中
type
TForm9 = class(TForm)
[...]
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
[...]
您将 AddSimpleElement
声明为 TForm9 class 的方法,但在此代码中
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
的实现,这与您的想法相反。相反,您声明了一个与 TForm9 完全无关的独立过程 AddSimpleElement。将您的代码更改为
procedure TForm9.AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
var
newElem : IXMLDOMElement;
begin
[...]
并且您将提高代码编译的机会。当然可能还有其他问题。
顺便说一句,这是一种很容易犯的错误,尤其是在漫长的一天结束时。您可以使用 IDE 的 "Class completion" 帮助来避免它。输入后
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
在 TForm9 的类型声明中,如果您按下 Ctrl-Shift-C,那么 IDE 将生成该方法的(空)实现并移动光标
顺便说一句,如果你不介意我说的话,你 q 的愚蠢部分包括完全无用的屏幕截图,但没有在你的 q 中提及编译器在以下情况下产生的错误消息的确切文本你试图编译你的代码。在这种情况下,您的代码中有一个明显的错误一目了然,但您确实应该在此处寻求帮助时尽量提供最好的信息。
下面是我 运行 的代码,但出现错误:
我已经检查过 uses
没问题。
我认为我的 AddSimpleElement()
程序的参数有问题。
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
我认为 "running" 不是正确的词,因为您显示的代码甚至无法编译,更不用说 运行.
在你的这部分代码中
type
TForm9 = class(TForm)
[...]
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
[...]
您将 AddSimpleElement
声明为 TForm9 class 的方法,但在此代码中
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
的实现,这与您的想法相反。相反,您声明了一个与 TForm9 完全无关的独立过程 AddSimpleElement。将您的代码更改为
procedure TForm9.AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
var
newElem : IXMLDOMElement;
begin
[...]
并且您将提高代码编译的机会。当然可能还有其他问题。
顺便说一句,这是一种很容易犯的错误,尤其是在漫长的一天结束时。您可以使用 IDE 的 "Class completion" 帮助来避免它。输入后
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
在 TForm9 的类型声明中,如果您按下 Ctrl-Shift-C,那么 IDE 将生成该方法的(空)实现并移动光标
顺便说一句,如果你不介意我说的话,你 q 的愚蠢部分包括完全无用的屏幕截图,但没有在你的 q 中提及编译器在以下情况下产生的错误消息的确切文本你试图编译你的代码。在这种情况下,您的代码中有一个明显的错误一目了然,但您确实应该在此处寻求帮助时尽量提供最好的信息。