-1

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.
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Ciodensky
  • 59
  • 1
  • 1
  • 11
  • Your image shows no error. It shows a red line that indicates one, but does not include an error message of any sort. What specifically is the error you're getting? There is very seldom a reason to post an image of your error; everything in Delphi's iDE allows you to copy the error message as text. Please do so. – Ken White Apr 09 '17 at 04:04

1 Answers1

3

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.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • Or, move the declaration that's in the form's class outside instead. The function has nothing to do with the form, so it's best to remove all dependencies too. You could even move it to a separate unit if you add more XML related functionality. – Wouter van Nifterick Apr 09 '17 at 07:17
  • @WoutervanNifterick: Indeed. – MartynA Apr 09 '17 at 07:26
  • @MartynA Thanks so much for the profound response. Really appreciate it! It answered my question very well. Cheers! – Ciodensky Apr 09 '17 at 12:22
  • @Cioden: glad it helped. – MartynA Apr 09 '17 at 12:57
  • 1
    @Cioden: Btw, please feel free to "accept" my answer by clicking the "tick" icon next to its top lefthand corner. That will increase your reputation slightly - as it increases you are permitted to do more things on SO. – MartynA Apr 09 '17 at 12:58