Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

xml - Procedure Parameter Error on MSXML

Below is the code that I am running and I am getting an error:

error screenshot

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...