TFilestream异常的原因是什么?

时间:2012-09-05 07:03:24

标签: delphi delphi-7

我有一个PNGObject和一个位图对象。有时是行

png:=TPNGObject.Create;
png.LoadFromFile(myfile);

被称为应用程序挂起,当我跟踪它时,我发现它在loadfromstream函数中引发了一个异常,但奇怪的是它并没有一直挂起。 所以任何人都可以告诉我这种异常的原因(流创建和从中读取) 以及如何检测c#中的异常消息,因为我无法找出异常的原因

修改 我知道在LoadFromFile中提升了这个例子,因为我在Tgraphics.LoadFromFile周围设置了一个try& catch 这是我操纵的代码:

procedure TGraphic.LoadFromFile(const Filename: string);
var
  Stream: TStream;
  x:integer;
  f:TextFile;
  path,logmessage:string;
begin
  try
    Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
    try
      try
      LoadFromStream(Stream);
      except
        on E : Exception do
        begin
          path:='C:\mylog'; 
          logmessage:= 'Error PNG LoadFromFile(LoadFromStream) '+E.Message+'::::'+E.ClassName ;
          try
            AssignFile(f,Path);
            if not(FileExists(Path))then
              ReWrite(f)
            else
              Append(f); {Opens the file for editing}
            Writeln(f, LogMessage);
            writeln(f,'==============================' );
            Closefile(f) ;
          except
            CloseFile(f);
          end;
      end;
      end;
    finally
      Stream.Free;
    end;
  except
        on E : Exception do
        begin
          path:='C:\mylog'; 
          logmessage:= 'Error PNG LoadFromFile(TFileStream.Create) '+E.Message+'::::'+E.ClassName;
          try
            AssignFile(f,Path);
            if not(FileExists(Path))then
            ReWrite(f)
            else
            Append(f); {Opens the file for editing}
            Writeln(f, LogMessage);
            writeln(f,'==============================' );
            Closefile(f) ;
          except
            CloseFile(f);
          end;
          end;
  end;
end;

这是应用程序挂起时我从这些行获得的异常:

错误PNG LoadFromFile(LoadFromStream)模块“myproject.exe”中地址0040A125处的访问冲突。读取地址00000254 :::: EAccessViolation

==============================

错误PNG LoadFromFile(LoadFromStream)模块“myproject.exe”中地址0040A125处的访问冲突。读取地址00000254 :::: EAccessViolation

==============================

错误PNG LoadFromFile(LoadFromStream)模块“myproject.exe”中地址0040A125处的访问冲突。读取地址000002DC :::: EAccessViolation9

==============================

错误PNG LoadFromFile(LoadFromStream)模块“myproject.exe”中地址0040A125处的访问冲突。读取地址00000254 :::: EAccessViolation

==============================

0 个答案:

没有答案