Link to home
Start Free TrialLog in
Avatar of moxum
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)
Avatar of kretzschmar
kretzschmar
Flag of Germany image

what about to use a TStringStream?
var str: string;

somwhere in read/write method: ...Pointer(str)^...

ziolko.
Avatar of krukmat
krukmat

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:string):TMemoryStream;
begin
  result:=TMemoryStream.Create;
  result.WriteBuffer(text,length(text));
  result.Seek(0,soFromBeginning);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  loadStringToStream(edit1.Text);
end;

end.
Avatar of moxum

ASKER

hmm that doesn't work... (and I also need a way to get the string... not only to store it...
ASKER CERTIFIED SOLUTION
Avatar of gecqo
gecqo

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