> 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
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
- I see MemoryStream having value of '()' in the Watch List before calling
Additionally, I see below code in TFtpClient code. I have no idea when that
TCustomFtpCli.DestroyLocalStream procedure around line no 2536:
if Assigned(FLocalStream) and (FStreamFlag = FALSE) then begin
FLocalStream := nil;
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:
if not Assigned(cls.DirStream) then
AddToLog(cls, '*** ERROR: LocalStream not assigned');
if cls.DirStream.Size = 0 then
AddToLog(cls, '*** ERROR: DirStream = 0');
cls.DirStream.Seek (0, soFromBeginning);
cls.FtpList := TStringList.Create;
try // finally
// load FTP file directory, make sure it's not empty
cls.FileNameList := TStringList.Create();
GetFileNamesFromFtpList(cls.FtpList, cls.FileNameList, ' ');
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