Creating XMLDOMDocument in Delphi

I'm trying to create a XMLDOMDocument in Delphi 6.0. I have the following code for that:

var
   XMLDoc : IXMLDOMDocument;
begin
   XMLDoc := CreateOleObject ('Microsoft.XMLDOM') as IXMLDomDocument;
   XMLDoc.async := False;
   //Statement for loading a file to that object...
end;

But I have errors:
1)"Undeclared identifier: 'IXMLDOMDocument'"
2)"Undeclared identifier: 'CreateOleObject'"
3)"Operator not applicable to this operand type" (This is for CreateOleObject statement)
4)"Missing operator or semicolon" (This is for XMLDoc.async statement)

What should I do to get rid of these errors? I need your answer as soon as possible. Thank you for your help...
LadybuggyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

andrewjbCommented:
You need to Component/Import ActiveX Control then look for the microsoft xml parser, and do import.
This gives you an MSXML2_TLB unit

'uses' this in your source file.

then the way I've used it before is something like

uses
  MSXML2_TLB;

var
  Doc : IXMLDomDocument;

begin

  Doc := CoDOMDocument.Create;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LadybuggyAuthor Commented:
In Import ActiveX Control list I don't have the Microsoft XML Parser. How can I have it in the list?
0
andrewjbCommented:
'Add', then browse to <Windows>/System32/ and look for, I think, msxml2.dll
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

LadybuggyAuthor Commented:
When I brosed System32/ directory I found 'msxml3.dll' and clicked to open. But nothing added to the list. What should I do now?
0
andrewjbCommented:
Err.. sorry. Have you got Project/Import Type Library.... That'd work better!

Ooops.
0
andrewjbCommented:
(You'll have to 'Add' again if it's not there already)
0
LadybuggyAuthor Commented:
I have tried several times but the result is the same... :(
0
andrewjbCommented:
What, on the import type library one?
0
LadybuggyAuthor Commented:
No, it was for Import ActiveX Control. Now I imported type library. I added 'uses MSXML2_TLB' and the program runs correctly till a statement that I tried to assign a XMLDOMDocument to a variable defined as IXMLDomDocument. It gives the error: 'Incompatible types: 'IDispatch' and 'IXMLDOMDocument''... Now what should I do?
0
andrewjbCommented:
Can you post a code snippet?
0
LadybuggyAuthor Commented:
Here the function 'TaminoNonXml1......' returns XMLDOMDocument...

var
   XMLDoc : IXMLDOMDocument;
begin
   XMLDoc := CoDomDocument.Create;
   XMLDoc.async := False;
   XMLDoc := TaminoNonXml1.SetNonXmlWithFilename(Null, 'D:\Pelin\Tez\&#304;çerik Geli&#351;tirme Arac&#305;\Gecici_Dosya.doc', 'application/msword');
end;
0
andrewjbCommented:
OK -that doesn't make sense. You don't need to create the CoDomDocument if the Temino... function is doing it for you...

You'll have to give a bit of the Tamino...SetNonXml..() function code, too.
0
LadybuggyAuthor Commented:
I just have the following information about this function, because that is an '.ocx' an I don't know inside of it:

SetNonXmlWithFilename
LPDISPATCH SetNonXmlWithFilename(BSTR lpszRelURL, BSTR lpszInputFile, BSTR lpszContentType)

Puts a document or file into the Tamino database.
Parameters:
lpszRelURL - NULL, or the relative URL added to the database URL if it does not begin with "http://
lpszFile - the name of the document or file to be read
lpszContentType - the value of the HTTP header "Content-Type" (e.g., "application/msword")
Return Type:
IXMLDOMDocument: DOM tree corresponding to response [if NULL use GetErrorStatus]
0
andrewjbCommented:
OK, so it returns you an IDispatch pointer, which is really pointing to an IXMLDomDocument.

You need to QueryInterface on the returned pointer. Hang on... i'll have to see how to do that in Delphi!

0
andrewjbCommented:
Hmmmm. Haven't got it installed here.

Right - try the following:

var
  Temp : IDispatch;
  res : integer;
begin
...

Temp = TaminoNonXml1.SetNonXmlWithFilename(....) etc.

then

res := Temp.QueryInterface( IXMLDOMDocument , XMLDoc);

and res should be zero, and your XMLdoc should be set.

But I can't try it!

0
LadybuggyAuthor Commented:
I wrote the code and put a breakpoint to the statement 'Temp := Tamino...'. It gives the following error to that statement at runtime: "Project *.exe raised exception class EVariantError with message 'Invalid variant type conversion'. Process stopped. Use Step or Run to continue."
0
andrewjbCommented:
OK - try just calling the function on it's own (don't assign the result to anything). Does that work? Which proves whether it's the function call that fails, or the assignment to Temp
0
LadybuggyAuthor Commented:
It gives the same error when I just called the function without assigning the result to something...
0
andrewjbCommented:
Try with a normal filename for a moment i.e. one without weird characters in it...

Then try passing '' as the first parameter instead of NULL (not what you want in the end, but we're trying to find where the problem lies)
0
andrewjbCommented:
Then try

var x: widestring

x := '......your filename'

and pass x as the parameter, instead of the string literal
(and do the same for the other 2 parameters)
0
LadybuggyAuthor Commented:
Good morning andrewjb... (It's morning here) I applied all you said... Now the code is like the following:

var
   XMLDoc : IXMLDOMDocument;
   Temp   : IDispatch;
   res    : Integer;
   relURL, FileName, ContentType : Widestring;
begin
   relURL      := 'D:\Pelin\Tez\&#304;çerik Geli&#351;tirme Arac&#305;\Gecici_Dosya.doc';
   FileName    := 'D:\Pelin\Tez\&#304;çerik Geli&#351;tirme Arac&#305;\Gecici_Dosya.doc';
   ContentType := 'application/msword';

   XMLDoc := CoDomDocument.Create;
   XMLDoc.async := False;
   Temp := TaminoNonXml1.SetNonXmlWithFilename(relURL, FileName, ContentType);
   res  := Temp.QueryInterface( IXMLDOMDocument , XMLDoc);
end;

1) It gives no error for "Temp := TaminoNonXml1..." statement, but after the execution of that statement, the Temp variable stays the same (Nil). Is this normal?
2) Now there is an error for the "res := Temp...". It says: "EAccessViolation with message 'Access violation at address XXX in module *.exe'" and the res variable is 0 before and after the execution of the statement. What should I do now?

Thanks for help...
0
andrewjbCommented:
No Temp shouldn't be nil. That means the SetNonXML.... didn't work.
OK. So we've sorted out that the original variant problem was with the strings, when you called the function.
Looking at your documentation, I don't think that relURL should be like that... you probably _do_ want to pass nil across.

So, try it with NULL or nil. We need 'Temp' to have a value when the function returns.

0
LadybuggyAuthor Commented:
I tried it like: "Temp := TaminoNonXml1.SetNonXmlWithFilename(Null, FileName, ContentType);" and it gives the error: "EVariantError with message 'Invalid variant type conversion'".

Itried it like: "Temp := TaminoNonXml1.SetNonXmlWithFilename('', FileName, ContentType);" and it returns the Temp variable nil. Gives address violation error to the next line.

I tried it like: "Temp := TaminoNonXml1.SetNonXmlWithFilename(nil, FileName, ContentType);" and it gives the error "Incompatible types: 'WideString' and 'Pointer'.
0
andrewjbCommented:
For pity's sake!

hang on a mo....
0
andrewjbCommented:
You must somewhere have a delphi prototype for the SetNonXMLWithFilename function. Could you post it, please.
0
LadybuggyAuthor Commented:
Can I look inside the '*.ocx' in Delphi?
0
LadybuggyAuthor Commented:
Where should I look for the prototype?
0
andrewjbCommented:
You must have imported the ocx to get a .pas file. Look in your 'uses' clause - is there something like TaminoNonXml or something? Otherwise, search all .aps files for 'SetNonXMLWithFilename' and you should find it!
0
LadybuggyAuthor Commented:
I can just find these lines in TAMINONONXMLLib_TLB.pas:

function  SetNonXmlWithFilename(const url: WideString; const inputFile: WideString; const contenttype: WideString): IDispatch; dispid 6;

function  TTaminoNonXml.SetNonXmlWithFilename(const url: WideString; const inputFile: WideString; const contenttype: WideString): IDispatch;
begin
  DefaultInterface.SetNonXmlWithFilename(url, inputFile, contenttype);
end;    
0
andrewjbCommented:
OK - that's what I needed. Not sure how Delphi deals with these WideStrings. COM calls only deal in BSTR (which are similar, but not the same...)

I'll have a look at this, but just for the moment, try setting
relURL := 'http://' and trying the last one again.

0
LadybuggyAuthor Commented:
The same: Temp is returned nil and in the next statement "Address Violation" error...
0
LadybuggyAuthor Commented:
Did you find something? I'm still at the same point... :(
0
HurremSultanCommented:
I also have something like that and it gives the same error... Aren't you going to help on this problem... I need the solution as soon as possible...
0
andrewjbCommented:
Right. Sorry - forgot about this one.

To pass a NULL across, you just use an empty string i.e. ''
 So, your call should look something like

Temp := TaminoNonXml1.SetNonXmlWithFilename('', FileName, ContentType);"

or maybe even better:

s : WideString;
s := '';
Temp := TaminoNonXml1.SetNonXmlWithFilename(s, FileName, ContentType);


If that still returns 'nil', then it's a problem with the SetNonXMLWithFilename() function, which doesn't like the values you are sending it for some reason. I don't know what this TaminoNonXML COM object does, so can't help any more than that....

0
LadybuggyAuthor Commented:
Both still returns 'nil'. But I recognized that although it returns nil, it writes the file to the database (this function writes a nonXML file to a XML database). Do you have any comment on that?

Thanks for assistance...
0
andrewjbCommented:
Right then. So call GetErrorStatus on the TaminoNonXML and see what that gives you. I presume you've some documentation for that function somewhere?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.