> Yes, but when you read or write a stream, the next read/write position is
where you last left it, and you probably read 
> beyond the stream end, and then got an AV trying to write there.  
> 
> Clear the stream before every request. 

Something is odd on my side and I cannot find it.

This is a single form application. Current code does below.
1- Create a MemoryStream and TFtpClient at the time form created.
2- It is only OnError and OnRequestDone events are assigned to FtpClient
component
3- MemoryStream is not touched if there is an error condition with the
download (I am not getting any error for the first pass in terms of ftp
download sequence anyway)
4- Do a MemoryStream.Clear just before each pass, before even starting a
connection (and I get AV right on the line I am doing Clear() for second
pass. First pass is fine)
5- Ftp.LocalStream is assigned to MemoryStream for each pass.
6- Do a MemoryStream.Free when form destroy (and I get another AV there if
there is one or more pass trials)

- There is no MemoryStrem.Free (or Ftp.LocalStream.Free) anywhere in my code
other than form destroy. 
- If it is not created, I would be getting an AV for the first pass.
- I see Assigned(MemoryStream) = True if I put a break point in the
debugging
- I see MemoryStream having value of '()' in the Watch List before calling
MemoryStream.Clear()

Additionally, I see below code in TFtpClient code. I have no idea when that
is triggered.

TCustomFtpCli.DestroyLocalStream procedure around line no 2536:
    if Assigned(FLocalStream) and (FStreamFlag = FALSE) then begin
        FLocalStream.Free;
        FLocalStream := nil;
    end;

Is it possible that run-time create of TFtpClient is setting FStreamFlag to
False? However, I should see MemoryStream to be nil in the Watch List. 

My code which is using the MemoryStream is like below. "Cls" is a class of
TMyClass that I defined to hold several other variables:
    ftpDirAsync:
    begin
      if not Assigned(cls.DirStream) then
      begin
        AddToLog(cls, '*** ERROR: LocalStream not assigned');
        Exit();
      end;

      if cls.DirStream.Size = 0 then
      begin
        AddToLog(cls, '*** ERROR: DirStream = 0');
        Exit();
      end;

      cls.DirStream.Seek (0, soFromBeginning);
      cls.FtpList := TStringList.Create;
      try  // finally
        // load FTP file directory, make sure it's not empty
        cls.FtpList.LoadFromStream(cls.DirStream);

        cls.FileNameList := TStringList.Create();
        try
          GetFileNamesFromFtpList(cls.FtpList, cls.FileNameList, ' ');

          cls.DownloadList.Clear();
          FilterFilesInList(cls.FileNameList, cls.DownloadList,
cls.DownloadFileMask);
        finally
          cls.FileNameList.Free();
        end;
      finally
        cls.FtpList.Free();
      end;

Just cannot see where the problem is.

Thanks for all your help.



-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to