Autor Beitrag
rd3
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 04.07.11 12:32 
Hallo,

ich hab mal eine Frage und steh auf dem Schlauch...

Mein Problem: Ich habe ein Binary-Feld (Blob) in einer MS SQL-Tabelle ind welches wahrscheinlich über C# per Serialization.Formatters geschrieben wurde, z.B. über folgende Methode (s. auch www.digitalcoding.co...bject-to-file.html):
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
public bool ObjectToFile(object _Object, string _FileName)
{
    try
    {
        // create new memory stream
        System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream();
        // create new BinaryFormatter
        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter
                    = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        // Serializes an object, or graph of connected objects, to the given stream.
        _BinaryFormatter.Serialize(_MemoryStream, _Object);
        // convert stream to byte array
        byte[] _ByteArray = _MemoryStream.ToArray();
        // Open file for writing
        System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        // Writes a block of bytes to this stream using data from a byte array.
        _FileStream.Write(_ByteArray.ToArray(), 0, _ByteArray.Length);
        // close file stream
        _FileStream.Close();
        // cleanup
        _MemoryStream.Close();
        _MemoryStream.Dispose();
        _MemoryStream = null;
        _ByteArray = null;
        return true;
    }
    catch (Exception _Exception)
    {
        // Error
        Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
    }
 
    // Error occured, return null
    return false;
}

Das ist wahrscheinlich eine XML-Datei..., die als Binary in dem Feld gespeichert wurde.

Wie kann ich über Delphi diesen Blob/dieses Feld wieder auslesen, damit ich daraus wieder eine XML machen kann?

Hat einer vielleicht eine Idee?

Danke und viele Grüße
rd3


Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am Mo 04.07.2011 um 12:47
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 04.07.11 17:07 
Prinzipiell gibt es zwei Möglichkeiten:

1. Du schreibst Dir eine kleine DLL in C#, die Dir die Konvertierung erledigt und die Du von deinem Delphi-Programm aus aufrufst

oder

2. Du schaust Dir das Format an und deserialisierst Dir das selber und konvertierst es direkt im Delphi-Programm.

Für den zweiten Schritt kannst Du ggf. einen Blick auf den Code des Formatters in C# werfen als Ausgangspunkt.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.