Link to home
Start Free TrialLog in
Avatar of BdLm
BdLmFlag for Germany

asked on

save and load msxml to Blob ...

now 2 function to load and store MSXM documents to a Blob ...
I'm in trouble using Streams
{**********************************************
 * in:
 *
 *  aTable       [paradox table]
 *  aXMLField    [fieldname]
 *  axmldoc      MSXML IXMLDomDocument
 *
 *  Support:   http://www.experts-exchange.com/Programming/Languages/Pascal/Q_23022273.html
 *             still i do something wrong ....
 **********************************************}
 procedure SaveXMLDocToTable(aTable: TTable; aXMLField : TBlobField; aXMLdoc : IXMLDomDocument);
 var   ss   : TStringStream;
 begin
 
   ss := TStringStream.Create(axmldoc.xml);
 
   with aTable do
      begin
         Edit;
 
         Try
 
          aXMLField.SaveToStream(ss);
           // use the ss
           // XMLStr := ss.ReadString(ss.Size);
        finally
            ss.free
        end;
 
      Post;
 
      end;
 
end;
 
{***********************************************
 *
 *  reverse function of above
 ***********************************************}
 
 procedure SaveTableToXMLDoc(aTable: TTable; aXMLField : TBlobField; var aXMLdoc : IXMLDomDocument);
 var   ss   : TStringStream;
 begin
 
   ss := TStringStream.Create('');
 
   with aTable do
      begin
         Edit;
 
         Try
 
            aXMLField.SaveToStream(ss);
 
            aXMLdoc.loadXML(ss.ReadString(ss.Size));
 
        finally
             ss.free;
        end;
 
      Post;
 
      end;
 
 
 
end;

Open in new window

SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

test on the function SaveTableToXMLDoc:

    ss.ReadString  need type TStringStream
but  then ss := aTable.CreateBlobStream(aXMLField, bmRead); is incorrect

Avatar of BdLm

ASKER

aXMLdoc : IXMLDomDocument  does not have a SaveToStream(ss)  methode, pls see
https://www.experts-exchange.com/questions/23022273/Delphi-save-MSXML-to-BLOB.html
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

@stevebay -> the first fct. now solved by myself, the second with your help
**********************************************
 * in:
 *
 *  aTable       [paradox table]
 *  aXMLField    [fieldname]
 *  axmldoc      MSXML IXMLDomDocument
 *
 *  Support:   http://www.experts-exchange.com/Programming/Languages/Pascal/Q_23022273.html
 *             still i do something wrong ....
 **********************************************}
procedure SaveXMLDocToTable(aTable: TTable; aXMLField : TBlobField; aXMLdoc : IXMLDomDocument);
var ss: TStringStream;
begin
 
  with aTable do
 
  begin
    Edit;
    try
       ss:=TStringStream.Create(aXMLDoc.xml);
 
       ss.position := 0;
 
       aXMLField.LoadFromStream(ss);
    finally
       FreeAndNil(ss);
    end;
    Post;
  end;
 
end;
 
{***********************************************
 *
 *  reverse function of above
 *  pass first tests !
 ***********************************************}
 
procedure SaveTableToXMLDoc(aTable: TTable; aXMLField : TBlobField; var aXMLdoc : IXMLDomDocument);
var ss: TStringStream;
begin
 
  ss:=TStringStream.Create('');
 
  with aTable do
  begin
 
    try
      aXMLField.SaveToStream(ss);
 
      ss.position := 0; // << ALWAYS reset stream position before reading
 
      aXMLdoc.loadXML(ss.ReadString(ss.Size));
    finally
      ss.free;
    end;
  end;
 
end;

Open in new window

keep create and free of object on same level

Otherwise you may have memory leaks


//ss:=TStringStream.Create('');
 
  with aTable do  // Level 1
  begin
    ss:=TStringStream.Create('');   // Level 2
    try
      aXMLField.SaveToStream(ss);
 
      ss.position := 0; // << ALWAYS reset stream position before reading
 
      aXMLdoc.loadXML(ss.ReadString(ss.Size));
    finally
      ss.free; // Level 2
    end;
  end; // Level 1

Open in new window

Avatar of BdLm

ASKER

good point, it is an important topic

would be nice if Borland can do this job for me with the next Delphi release ...