This warning appears, because F can be equal to nil if TFileStream.Create
raises exception. In this case youll handle exception, but not initialize
your variable F.
Sorry for my poor english :)
Message
From: "Wilfried Mestdagh" <wilfried (AT) mestdagh (DOT) biz>
To: "'Delphi-Talk Discussion List'" <delphi-talk (AT) elists (DOT) org>
Sent: Sunday, 23, 2005 9:28 PM
Subject: compiler warning
Hello,
I have a compiler warning in following code 'F might not be
initialized', at the M.LoadFromStream(F); line.
M := TMemoryStream.Create;
try
for n := 0 to FFiles.Count - 1 do begin
try
F := TFileStream.Create(FFiles[n], Read or
fmShareDenyWrite);
except
TriggerWarning('Could not open ''' + FFiles[n] + '''');
Continue;
end;
M.LoadFromStream(F);
F.Free;
if not DeleteFile(FFiles[n]) then
TriggerWarning('Cannot delete file ''' + FFiles[n] + ''', will not
transmit it.')
else
// Todo: add to database and transmit it
end;
finally
M.Free;
end;
However unless my brain is damaged due to late hours work, it should
always be initialized because if exception occure I 'continue' the loop.
The TriggerWarning fires an event (yeah I know DoWarning is be more
used), and FFiles is a TStringList containing filenames in a given
folder.
What I'm trying to do is read files generated by another application,
open them, do something with it and delete it. The other application may
not change the file after I open it of course.
Can I make the compiler happy, or make some better code to etablish this
?
Rgds, Wilfried
http://www.mestdagh.biz
Delphi-Talk mailing list -Delphi-Talk (AT) elists (DOT) org
Delphi-Talk mailing list -Delphi-Talk (AT) elists (DOT) org