Re: How can I convert this method to be compatible with the latest Indy version?

Giganews Newsgroups
Subject: Re: How can I convert this method to be compatible with the latest Indy version?
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Wed, 7 Dec 2005

"Stephane Wierzbicki" <swierzbic…@free.fr> wrote in message
news:3E7032F0A5E4E240swierzbic…@free.fr...

> Can someone be kind and point me what to change ?

TIdStreamVCL no longer exists.  You don't need the Wrapper anymore, you can
pass your TStream in directly:

    function SendFileToServer(AClient: TIdTCPClient; AFilename, ASiteId:
String): Boolean;
    var
        FileStream: TFileStream;
    begin
        Result := False;
        try
            FileStream := TFileStream.Create(AFilename, fmOpenRead or
fmShareDenyWrite);
            try
                AClient.SendCmd('FILE|' + ExtractFileName(AFilename) + '|' +
IntToStr(FileStream.Size) + '|' + ASiteID,  100);
                AClient.IOHandler.Write(FileStream, 0);
                AClient.GetResponse(100);
                Result := True;
            finally
                FreeAndNil(FileStream);
            end;
        except
            on E: Exception do
            begin
                // handle an error...
                ShowMessage(E.Message);
            end;
        end;
    end;

Alternatively, use Indy's wrappers, which are available in both Win32 and
.NET:

    uses IdSys;

    function SendFileToServer(AClient: TIdTCPClient; AFilename, ASiteId:
String): Boolean;
    var
        FileStream: TIdFileStream;
    begin
        Result := False;
        try
            FileStream := TIdFileStream.Create(AFilename, fmOpenRead or
fmShareDenyWrite);
            try
                AClient.SendCmd('FILE|' + Sys.ExtractFileName(AFilename) +
'|' + Sys.IntToStr(FileStream.Size) + '|' + ASiteID,  100);
                AClient.IOHandler.Write(FileStream, 0);
                AClient.GetResponse(100);
                Result := True;
            finally
                Sys.FreeAndNil(FileStream);
            end;
        except
            on E: Exception do
            begin
                // handle an error...
                ShowMessage(E.Message);
            end;
        end;
    end;

Gambit

Replies

None

In response to

How can I convert this method to be compatible with the latest Indy version? posted by Stephane Wierzbicki on Wed, 07 Dec 2005