You are not logged in.
Pages: 1
Is there somethings link StreamFromString and StringFromSteam functions?
I need save and load a graph generate by a VCL component, this component have LoadFromStream and SaveToStream methods.
Thanks
Offline
I just use it but I get some problem. I post some piece of code.
This is my TSQLRecord:
TSQLNotes = class(TSQLRecord)
private
fRecordCreated: TCreateTime;
fRecordModified: TModTime;
fParent: Integer;
fKind: Integer;
fTitle: RawUTF8;
fNote: RawUTF8;
fText: RawUTF8;
published
property RecordCreated: TCreateTime read fRecordCreated write fRecordCreated;
property RecordModified: TModTime read fRecordModified write fRecordModified;
property Parent: Integer read fParent write fParent;
property Kind: Integer read fKind write fKind;
property Title: RawUTF8 read fTitle write fTitle;
property Note: RawUTF8 read fNote write fNote;
property Text: RawUTF8 read fText write fText;
end;
I need save and load a graph generate from TSimpleGraph, so I use this code to save the graph:
Stream := TRawByteStringStream.Create;
Stream.Position := 0;
SimpleGraph.SaveToStream(Stream);
NotaRecord.Note := S2U(Stream.DataString);
Stream.Free;
and then I try to load it with this code:
Stream := TRawByteStringStream.Create;
try
NotaRecord := TSQLNotes.Create(Database,'ID=?',[idRow]);
WriteStringToStream(Stream, NotaRecord.Note);
if (Stream.Size > 0) and (NotaRecord.Note <> '') then
begin
Stream.Seek(0,soBeginning);
SimpleGraph.LoadFromStream(Stream);
end;
NotaRecord.Free;
finally
Stream.Free;
end;
However TSimpleGraph return exception when LoadFromStream is call because the stream format is not correct.
What am I doing wrong?
Thanks
Offline
WriteStringToStream() is not to be used like this!
As stated by the doc, it is a wrapper to be used with our binary stream format.
Just use Stream := TRawByteStringStream.Create(NotaRecord.Note).
And IMHO you should better define the Note field as TSQLRawBlob and not RawUTF8.
Your content is NOT UTF-8 text, but raw binary, right?
Offline
Pages: 1