Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-07

how to TXMLPropStorage SaveToStream() LoadFromStream

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

FreeMan

without savefile to disk

type
   TmyCustomXMLPropStorage = class(TCustomXMLPropStorage);
   { TForm1 }
   TForm1 = class(TForm)
     XMP: TXMLPropStorage;
...
procedure TForm1.Button1Click(Sender: TObject);
var st : TStream;
begin
   try
   st := TStream.Create;
    TmyCustomXMLPropStorage(XMP).XMLConfig.SaveToStream(st);
    memo1.Lines.LoadFromStream(st);
    //TmyCustomXMLPropStorage(XMP).XMLConfig.LoadFromStream(st);
   finally
     st.Free;
   end;
end;

Reply by email

FreeMan
to Virgo Pärna

Thanks your suggestion, I need similar TXMLPropStorage.SaveToStream() and TXMLPropStorage.LoadFromStream(). Iwanna save and load xml doc to Tstream.

this is in lfm:
object xmp: TXMLPropStorage
StoredValues = <
item
Name = '1111'
Value = '11111'
KeyString = '111'
end
item
Name = '22'
Value = '222'
KeyString = '2'
end>
left = 24
top = 16
end

procedure TForm1.Button1Click(Sender: TObject);
var st : TMemoryStream;
begin
try
st := TMemoryStream.Create;
TmyCustomXMLPropStorage(XMP).XMLConfig.SaveToStream(st);
memo1.Lines.LoadFromStream(st);
//TmyCustomXMLPropStorage(XMP).XMLConfig.LoadFromStream(st);
finally
st.Free;
end;
end;

and result :
Project project1 raised exception class 'External: SIGSEGV'.

02-07-2014 16:30 tarihinde, Virgo P?rna yazd?:

Show quoted text 6 lines
On Wed, 02 Jul 2014 15:56:57 +0300, FreeMan wrote: > without savefile to disk > TMemoryStream

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140702/41a76027/attachment.html>

Reply by email

Virgo Pärna
to FreeMan
FreeMan wrote 6 lines
procedure TForm1.Button1Click(Sender: TObject); var st : TMemoryStream; begin try st := TMemoryStream.Create;

You should creat st before try. Or at least set st to nil.

TmyCustomXMLPropStorage(XMP).XMLConfig.SaveToStream(st);

You save data to the stream.

memo1.Lines.LoadFromStream(st);

And now you read 0 bytes from stream (because current position of stream is at the end of stream.

and result : Project project1 raised exception class 'External: SIGSEGV'.

At which line that error occured?
TXMLConfig does not seem to have SaveToStream method. Which class has this method?

Virgo P?rna

Reply by email

FreeMan
to Virgo Pärna

I add my test project.

03-07-2014 11:34 tarihinde, Virgo P?rna yazd?:

At which line that error occured? TXMLConfig does not seem to have SaveToStream method. Which class has this method?
TmyCustomXMLPropStorage(XMP).XMLConfig.SaveToStream(st);//error is hear
XMLConfig is NIL !!!

if you use, ctrl + left click can see function and procedure .

My plan was use this component in my project, just add storedvalues, savetostream and sent this data via tcp client to server. I can use tstringlist but I have to write parse code
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_TXMLPropStorage.zip
Type: application/x-zip-compressed
Size: 66876 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140703/9abca7c2/attachment-0001.bin>

Reply by email

Virgo Pärna
to FreeMan
FreeMan wrote 8 lines
I add my test project. 03-07-2014 11:34 tarihinde, Virgo P?rna yazd?: > At which line that error occured? TmyCustomXMLPropStorage(XMP).XMLConfig.SaveToStream(st);//error is hear XMLConfig is NIL !!!

From LCL source TCustomXMLPropStorage.StorageNeeded Creates XMLConfig. And now I noticed, that TPropStorageXMLConfig indeed has stream methods. So - calling StorageNeeded before using XMLConfig should work (I have never used that component). And also remember to seek to beginning before reading from stream.

Virgo P?rna

Reply by email