Page 1 of 1

Access violation with PNG inside table.

Posted: Thu Dec 17, 2009 2:11 am
by Marsianin
Delphi 2010, RVE 12.0.4, 5x5 table, TPNGObject (from PNGComponents adapted to D2010).
Inserting PNG picture into the table cell then pressing center alignment button raises Access Violation in RVERVData.pas here:

Code: Select all

function TRVEditRVData.GetCurItemNo: Integer;
  {........................................}
  function IndexOf(obj: TCustomRVItemInfo): Integer;
  var ItemNo: Integer;
  begin
    Result := -1;
    if (CaretDrawItemNo>=0) and (CaretDrawItemNo<DrawItems.Count) then begin
      ItemNo := DrawItems[CaretDrawItemNo].ItemNo;         <<<-----<<<-----[HERE]-----
      if (ItemNo>=0) and (ItemNo<Items.Count) and (GetItem(ItemNo)=obj) then
        Result := ItemNo;
    end;
    if Result<0 then
      Result := Items.IndexOfObject(obj);
  end;
  {........................................}
begin
  PrepareForEdit;
...

Posted: Thu Dec 17, 2009 7:05 am
by Marsianin
It seems TPNGObject is a problem.
Moved to internal Delphi 2010 TPNGImage and it seems everything works fine here.

But now I have another problem. Previously I inserted PNG images from TPNGImageList into RVE with this code:

Code: Select all

procedure TMainForm.PicturesPaletteCellClick(Sender: TObject; ACol, ARow: Integer; var Allow: Boolean);
var png:TPNGObject;
begin
  png:=TPNGObject.Create;
  png.Assign(DM.ImageList2.PngImages.Items[ARow*PicturesPalette.RowCount+ACol].PngImage);
  RichViewEdit1.InsertPicture('',png,rvvaAbsBottom);
  Allow:=False;
end;
But now it's doesn't works because TImageList has only GetBitmap and GetIcon routines. But I want to insert PNG.
Is there a solution? Also I'm looking how can I save PNG image from TImageList to file on disk.

Posted: Thu Dec 17, 2009 9:04 am
by Sergey Tkachenko
What happens if you get image from image list as an icon, and then assign TIcon to png?

Posted: Sun Jan 17, 2010 7:33 pm
by Marsianin
I cannot assign TIcon to TPNGImage.
This will not work:
PNGImage.Assign(TIcon)

but this will:
PNGImage.Assign(TBitmap)

But using bitmap loses transparency :(

Found a code inside PNGComponents on how to convert ICO to PNG...it's a big procedure. Should be easier for D2009/2010