[fpc-devel]Weird isn't it ?
Michael.VanCanneyt at Wisa.be
Michael.VanCanneyt at Wisa.be
Wed Feb 12 21:39:30 CET 2003
On Wed, 12 Feb 2003, Maly wrote:
> Hi,
>
> i wrote some unit to handle my own FS :> but that's not
> important. well, i've got a constructor looking like this:
>
> constructor CFile.Create(var AFS:CDataFile;APath:string);
> var SavedPath : string;
> begin
> FFS:=AFS;
> SavedPath:=AFS.GetCurrentPath;
> // Writeln(SavedPath);
> FFileName:=CopyUntilReversed(APath,'/');
> FFilePath:=APath;
> AFS.ChDir(FFilePath);
> FIndex:=AFS.GetFileID(FFileName);
> if FIndex=0 then
> raise EDataFileException.Create('file '+APath+'doesn''t exist');
> if FFS.Header.Files[FIndex].IsCompressed then
> DataStream:=TDataFileCompressedStream.Create(FFS,FIndex)
> else
> DataStream:=TDataFileStream.Create(AFS,FIndex);
> FFS.ChDir(SavedPath);
> end;
>
> this code is 100% correct,
It is not. You should AT LEAST put the
AFS.ChDir(FFilePath);
FFS.ChDir(SavedPath);
In a try/finally block:
AFS.ChDir(FFilePath);
Try
FIndex:=AFS.GetFileID(FFileName);
if FIndex=0 then
raise EDataFileException.Create('file '+APath+'doesn''t exist');
if FFS.Header.Files[FIndex].IsCompressed then
DataStream:=TDataFileCompressedStream.Create(FFS,FIndex)
else
DataStream:=TDataFileStream.Create(AFS,FIndex);
Finally
FFS.ChDir(SavedPath);
end;
This is one thing. Secondly, it sounds like you have some memory buffer
overrun. Did you try using the -gh option ? the heaptrc unit gives you some
extra possibilities.
> but in some specific circumstances
> it works buggy, the variables(class's fields) have weird
> values(like 0 or ''). when I uncomment the commented line
> the results are ok. so how's that possible a writeln can
> fix the code? it does only print the 'debug-info' :>? it
> shouldn't change anything. the point is i don't need that
> line infact i don't want it at all. :/
> i guess it has something to do with optimiser.
Did you try running the code without optimization ?
Michael.
More information about the fpc-devel
mailing list