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

Giganews Newsgroups
Subject: How can I convert this method to be compatible with the latest Indy version?
Posted by:  Stephane Wierzbicki (swierzbic…@free.fr)
Date: Wed, 07 Dec 2005

Hi,

I'm a little bit lost, I first move my prject from Indy 9 to Indy 10, I
needed to change everything related with Stream. Now, I'm moving from
Indy 10 to indy 10.1 and my code is broken.

Here is one of a no more working method.
Can someone be kind and point me what to change ? This would be vry
friendly.

I tried to change the TIdStreamVCL to TStream, but I can't get it working !

function
SendfileToServer(AIdTCPClient:TidTCPClient;AFilename,ASiteId:string):boolean
;
var
LWrapper : TIdStreamVCL;
FileStream: TFileStream;
LStreamSize : int64;
Begin
try
          result:=false;
          FileStream:= TFileStream.Create(AFilename,fmOpenRead or
fmShareDenyWrite);
            try
              LWrapper := TIdStreamVCL.Create(FileStream);
              try
                if AIdTCPClient.SendCmd('FILE'+'|'+
extractfilename(AFilename) +'|'+IntToStr(LWrapper.VCLStream.Size)
+'|'+ASiteID) <> 100 then
                begin
                // handle the error in SendCmd() as needed...
                ShowMessage(AIdTCPClient.LastCmdResult.Text.Text);
                end else
                begin
                  AIdTCPClient.IOHandler.Write(LWrapper,0);
                  if AIdTCPClient.GetResponse([]) <> 100 then
                  begin
                    // handle the error in GetResponse() as needed...
                    result:=false;
                    ShowMessage(AIdTCPClient.LastCmdResult.Text.Text);
                  end else
                  Begin
                    result:=true;
                  End;
                End;
              finally
                FreeAndNil(LWrapper);
              end;
            finally
                FreeAndNil(FileStream);
            end;
        except
        on E: Exception do
          begin
            // handle an unexpected error...
            result:=false;
            ShowMessage(E.Message);
          end;
        end;
End;

thank you

Replies