views:

579

answers:

5

Delphi 6 on Vista service pack 2 seems that can't load imagelist from dfm and save back again in the IDE. The project with the dfm corrupted can't be rebuilt.

the error when I run the project is:

EReadError Error reading imagelist1.Bitmap: Failed to read ImageList data from stream

any suggestion?

thanks in advance

+1  A: 

Upgrade your Delphi.

gabr
+1  A: 

Try running Delphi as an administrator. Do you still get the error?

JosephStyons
+1  A: 

The problem may be on ImageList_Write of the comctl32.dll

// delphi 6
procedure TCustomImageList.WriteData(Stream: TStream);
var
  SA: TStreamAdapter;
begin
  SA := TStreamAdapter.Create(Stream);
  try
    if not ImageList_Write(Handle, SA) then
      raise EWriteError.CreateRes(@SImageWriteFail);
  finally
    SA.Free;
  end;
end;

// delphi 2005
procedure TCustomImageList.WriteData(Stream: TStream);
var
  SA: TStreamAdapter;
  ComCtrlHandle: THandle;
const
  ILP_DOWNLEVEL = 1;
begin
  if CachedComCtrlVer = 0 then
  begin
    CachedComCtrlVer := GetFileVersion(comctl32);
    if CachedComCtrlVer >= ComCtlVersionIE6 then
    begin
      ComCtrlHandle := GetModuleHandle(comctl32);
      if ComCtrlHandle <> 0 then
        ImageListWriteExProc := GetProcAddress(ComCtrlHandle, 'ImageList_WriteEx'); { Do not localize }
    end;
  end;

  SA := TStreamAdapter.Create(Stream);
  try
    { See if we should use the new API for writing image lists in the old
      format. }
    if Assigned(ImageListWriteExProc) then
    begin
      if ImageListWriteExProc(Handle, ILP_DOWNLEVEL, SA) <> S_OK then
        raise EWriteError.CreateRes(@SImageWriteFail)
    end
    else if not ImageList_Write(Handle, SA) then
        raise EWriteError.CreateRes(@SImageWriteFail);
  finally
    SA.Free;
  end;
end;
+7  A: 

Have you done anything funny to your Delphi installation, such as adding a delphi32.exe.manifest file to Delphi's directory in an attempt to make the IDE have XP or Vista theming? Don't do that. If you have that file there, delete it, and you should be back to normal.

The image-list format changed with version 6 of the Common Controls library, and Delphi 6 is not capable of using it. The manifest tells the IDE to use version 6, so when it saves your DFM, it uses that format. Then, when loading, prior versions can't read it anymore.

Rob Kennedy
+1  A: 

The problem is the delphi32.exe.manifest file!

Thanks to all and specially to Rob Kennedy

Max

You should mark Rob's post as the accepted one, so he'll get the reputation points (not that he needs them <g>).
Ken White