问题
Below is the code that I am running and I am getting an error:
I already checked the uses
and it's fine.
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.
回答1:
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.
In this part of your code
type
TForm9 = class(TForm)
[...]
procedure AddSimpleElement(doc : DOMDocument40; parent : IXMLDOMElement; name, value : String);
[...]
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
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.
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);
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.
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.
来源:https://stackoverflow.com/questions/43302716/procedure-parameter-error-on-msxml