Re: Access violation in TJPEGImage on W2K and XP



The dormat and stuff are new, the original code was:

if (LowerCase(ExtractFileExt(sFilename)) = '.jpg') or
(LowerCase(ExtractFileExt(sFilename)) = '.jpeg') then
begin
{ delete old bitmapfile }
DeleteFile(PChar(WindowsDir + sWinImgFile));
{ converts the image }
try
BitmapImage := TBitmap.Create;
JPEGImage := TJPEGImage.Create;
if FileExists(sFilename) then
JPEGImage.LoadFromFile(sFilename)
else
JPEGImage.LoadFromFile(WindowsDir + sFilename);
BitmapImage.Assign(JPEGImage);
BitmapImage.SaveToFile(WindowsDir + sWinImgFile);
BitmapImage.Free;
JPEGImage.Free;
except
BitmapImage.Free;
JPEGImage.Free;
end;
end;


I agree that the finally should be better, but that is really not the
problem, nor Dormat or those.
I have played with this for some time, and by removing the Assign it
does no longer give the access violation.

The code is so simple, yes, it should work.
But it does not explain the access violation when closing the app.

That is my main point.

Best regards
Sonnich

.