0

I continually get an access violation at read of address 0xfeeefeee where the debugger stops on the Ntdll.NtRaiseException, I can not debug further as I get a loop condition telling me that the app has faulted at ... Use step or run... and this takes me back to the beginning. This obviously only happens in the IDE (Delphi XE2) 32 bit. My application is using the following bits of code

Var
  XMLDoc: IXMLDocument;

Begin

  If FOD.Execute Then //File Open Dialog

  Begin
    Try

      Try

        XMLdoc := NewXMLDocument(); //TXMLDocument.Create(Nil);

        Result := FOD.FileName;

        XMLDoc.FileName := XMLFilename;

        XMLDoc.Active := True;

when the file opens I call functions loaded from the xml data binding wizard (File New Other XML) to parse the xml file opened in the proc above. My intent is just to create a csv file and then use sqlldr to export the data to an oracle database. Outside of the IDE all works find, and I can leave the application running just showing the data in a sring grid overnight but in the ide it crashes within minutes. The call stack shows me nothing usefull. As you can see I have tried TXMDocument.create, as well as NewXML but to no avail. I have tried putting the object on the form and using that instance to no avail. Anyone please have any ideas. (Windows 7 64 bit, but I am complining into 32 bit due to the oracle depenancies)

Edit, The call stack even with debug dcus switched on shows nothing of use just references to ole32.dll and other nt related dlls

The code for the app is shown below (some of it)

Function TXMLForm.OpenFile: String;
Var
  XMLDoc: IXMLDocument;
Begin
  If FOD.Execute Then
  Begin
    Try
      Try
        XMLdoc := NewXMLDocument(); //TXMLDocument.Create(Nil);
        Result := FOD.FileName;
        XMLDoc.FileName := XMLFilename;
        XMLDoc.Active := True;
        SB1.Panels[1].Text := FOD.Filename;
      Finally
        // xmldoc := nil;
      End;
    Except
      On E: Exception Do
        ShowMessage('Excpetion in Opening or creating XML Document. ' + E.Message);
    End;
  End
  Else
    Result := '';
End;

The openfile is called by this type of procedure

Procedure TXMLForm.StandardProfile1Click(Sender: TObject);
Var
  Stand: Standard.IXMLProfileData;
  I, X: Integer;
Begin
  XMLFileName := Openfile;
  If Xmlfilename <> '' Then
  Begin
    Stand := Standard.LoadProfileData(XMLFileName);
    SG1.RowCount := Stand.Count;
    Sg1.ColCount := Stand.Device[Stand.Count - 1].Count + 7;
    // SG1.ColCount := 55;
    SG1.Cells[0, 0] := 'SERIALNO';
    SG1.Cells[1, 0] := 'MFGSERIALNO';
    SG1.Cells[2, 0] := 'SUPPLYTYPE';
    SG1.Cells[3, 0] := 'SERVICEPOINTNO';
    SG1.Cells[4, 0] := 'PARAMETERCODE';
    SG1.Cells[5, 0] := 'INTERVALPERIOD';
    SG1.Cells[6, 0] := 'STARTTIME';
    // For X := 0 To 47 Do
    // SG1.Cells[7 + X, 0] := 'INTERVAL' + Inttostr(X);
    For X := 0 To Stand.Device[Stand.Count - 1].Count - 1 Do
      SG1.Cells[7 + X, 0] := 'INTERVAL' + Inttostr(X);

    For I := 0 To Stand.Count - 1 Do
    Begin
      SG1.Cells[0, I + 1] := Stand.Device[I].SerialNo;
      SG1.Cells[1, I + 1] := Stand.Device[I].MfgSerialNo;
      SG1.Cells[2, I + 1] := Stand.Device[I].SupplyType;
      SG1.Cells[3, I + 1] := Stand.Device[I].ServicePointNo;
      SG1.Cells[4, I + 1] := Stand.Device[I].ParameterCode;
      SG1.Cells[5, I + 1] := Stand.Device[I].IntervalPeriod;
      SG1.Cells[6, I + 1] := Stand.Device[I].StartTime;
      // For X := 0 To 47 Do
      For X := 0 To Stand.Device[Stand.Count - 1].Count - 1 Do // 47
       Begin
        If Stand.Device[I].Interval[X] = '' Then
          SG1.Cells[7 + X, I + 1] := 'TRUE'
        Else
          SG1.Cells[7 + X, I + 1] := Stand.Device[I].Interval[X];
      End;
    End;
  End;
End;

As stated before I have tried using the TXMDocument, the IXMLDocument and using Create and NewXMDocument but this still gives the errors. DEbug dcus' makes no difference. I have tired using FastMM4 in the project header and MadExcept but they don't catch the error.

imcpu2
  • 1
  • 1
  • 1
    maybe stack trace would show more useful if checking "use debug DCUs" – Arioch 'The Apr 18 '13 at 10:03
  • +1 for Use debug dcus, but what makes you think this is the code that is causing the error? Have you tried an app with just this code? There's nothing there that would cause any error. Maybe show the full function and how/where it's called – Jason Apr 18 '13 at 10:04
  • duplicate ? http://stackoverflow.com/questions/8398703/delphi-txmldocument-created-at-run-time-generates-av-with-component-on-the-fo – RBA Apr 18 '13 at 10:08
  • Do you have the same problem if you use `LoadXMLDocument()` instead of `NewXMLDocument()`? `XMLdoc := LoadXMLDocument(FOD.FileName);` If you are running on Windows, did you call `CoInitialize/Ex()` beforehand? – Remy Lebeau Apr 18 '13 at 19:01
  • your XMLDoc variable is a local document. Apart from opening the xml file in OpenFile, you're not doing anything with it. Is that full code for OpenFile? Can you declare XMLDoc in the private section of TXMLForm - have you got another variable somewhere called XMLDoc which you're inadvertently referring to thinking it's this XMLDoc? As it stands, the OpenFile method doesn't really do anything with XMLDoc. It just verifies that the file can be opened, really, which may be the point, but you certainly can't access the XmlDocument outside of this function - particularly with local variable. – Jason Apr 18 '13 at 22:02
  • Ah, thanks Remy. CoInitialize did the trick. I had forgoten all about that, and it does make sense now when my callstack seemed to point to ole32. Initial test show that this is now fine in the IDE. Many thanks to all for comments and suggestions. – imcpu2 Apr 19 '13 at 07:36

2 Answers2

0

You don't show all the code handling XMLDoc; maybe you're freeing it?

"When TXMLDocument is created without an Owner, it behaves like an interfaced object. That is, when all references to its interface are released, the TXMLDocument instance is automatically freed. When TXMLDocument is created with an Owner, however, it behaves like any other component, and is freed by its Owner." See Delphi - TXMLDocument created at run-time generates AV, with component on the form is working

Also when done with, set XMLDoc := nil;

Community
  • 1
  • 1
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • Thanks, but I have not freed this object, I tried that with the same errors so did'nt bother I tried setting to nil, but this did not work either. – imcpu2 Apr 18 '13 at 09:13
0

Thanks to Remy, the problem is solved. This was indeed a case of CoInitialize not being called. I totaly forgot about this.

imcpu2
  • 1
  • 1