I have found that Delphi always generates this warning when an
assignment is in a try block and you want to use the variable outside
the try block. The easiest way to get around this is to just put: F :=
nil right before the try block;

I think that Delphi does not actually figure out all possible paths to
generate this warning. It just bases its logic of some basic rules.
These rules likely just treat the "continue" as a normal function and it
does not consider its somewhat non-standard logic.
 
This is just my best guess as to why it happens.

- Mark





-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Wilfried Mestdagh
Sent: Sunday, October 23, 2005 2:29 PM
To: 'Delphi-Talk Discussion List'
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], fmOpenRead 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 -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to