moxum
asked on
string to memory stream and back.
Problem:
I have a string that I want to save in a memory stream, send the stream via indy over a socket fetch it in another stream at the other side and retreive the string again.
(I only need the string and stream part, not the socket stuff)
I have a string that I want to save in a memory stream, send the stream via indy over a socket fetch it in another stream at the other side and retreive the string again.
(I only need the string and stream part, not the socket stuff)
what about to use a TStringStream?
var str: string;
somwhere in read/write method: ...Pointer(str)^...
ziolko.
somwhere in read/write method: ...Pointer(str)^...
ziolko.
try this:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function loadStringToStream(text:st ring):TMem oryStream;
begin
result:=TMemoryStream.Crea te;
result.WriteBuffer(text,le ngth(text) );
result.Seek(0,soFromBeginn ing);
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
loadStringToStream(edit1.T ext);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function loadStringToStream(text:st
begin
result:=TMemoryStream.Crea
result.WriteBuffer(text,le
result.Seek(0,soFromBeginn
end;
procedure TForm1.Button1Click(Sender
begin
loadStringToStream(edit1.T
end;
end.
ASKER
hmm that doesn't work... (and I also need a way to get the string... not only to store it...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.