Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Apr : Re: TidStreamVCL or TIdStreamVCLWin32???

www.cryer.info
Managed Newsgroup Archive

Re: TidStreamVCL or TIdStreamVCLWin32???

Subject:Re: TidStreamVCL or TIdStreamVCLWin32???
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Fri, 7 Apr 2006 11:02:53

"Jacques Noah" <jacques.noah@btinternet.com> wrote in message
news:44359b6c$1@newsgroups.borland.com...

> Thank you for your reply, i still do not know what to leave out and
> what to include when sending and recieving files through streams.

I already told you exactly what to do - get rid of TIdStreamVCL completely
from your code, and just pass your stream in directly everywhere you were
previously passing in TIdStreamVCL, ie:

    --- server ---

    var
        MStream: TMemoryStream;
    begin
        MStream := TMemoryStream.Create;
        try
            AContext.Connection.IOHandler.ReadStream(MStream);
            mstream.SaveToFile(filename);
        finally
            MStream.Free;
        end;
    end;


    --- client ---

    var
        FStream: TFileStream;
    begin
        FStream := TFileStream.Create(fn, fmOpenRead or fmShareDenyWrite);
        try
            Context.Connection.IOHandler.Write(FStream, 0, True);
            Context.Connection.IOHandler.WriteLn('done!');
        finally
            FStream.Free;
        end;


Now, if you want your code to be portable to other platforms, then use
Indy's own stream types instead:

    --- server ---

    var
        MStream: TIdMemoryStream;
    begin
        MStream := TIdMemoryStream.Create;
        try
            AContext.Connection.IOHandler.ReadStream(MStream);
            mstream.SaveToFile(filename);
        finally
            MStream.Free;
        end;
    end;


    --- client ---

    var
        FStream: TIdReadFileExclusiveStream;
    begin
        FStream := TIdReadFileExclusiveStream.Create(fn);
        try
            Context.Connection.IOHandler.Write(FStream, 0, True);
            Context.Connection.IOHandler.WriteLn('done!');
        finally
            FStream.Free;
        end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive