After searching around for along time... I've found nothing.

I need to be able to grab an image from an imagelist. I tried searching through the properties and methods, but found nothing that looked like it would help.

begin
             PicArray[WhichCol, WhichRow].Picture := {Image from imagelist}
             end;
             until Imageindex[WhichCol, WhichRow] = I;

where outlined in curly braces is the assignment

Recommended Answers

All 3 Replies

Learn to read the documentation. The note says it all. I already wrote that you invented the wheel in an array. Now you again that it invents. It's time to read and not poke your finger into the sky.

way 1

procedure TSecondForm.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
  idx: Integer;
begin
   bmp := TBitmap.Create;
   try
     for idx := 0 to ImageList.Count - 1 do
      begin
         ImageList.GetBitmap(idx,bmp);
         Canvas.Draw(0,idx*bmp.Height,bmp);
      end;
   finally
     bmp.Free;
   end;
end;

way 2

procedure TSecondForm.Button2Click(Sender: TObject);
var
  idx: Integer;
begin
  for idx := 0 to imageList.Count - 1 do
    ImageList.Draw(Canvas,0,idx*ImageList.Height,idx);
end;

I would have done something like this code:

procedure TSecondForm.Button3Click(Sender: TObject);
var
  bmp: TBitmap;
  idx,i: Integer;
begin
   bmp := TBitmap.Create;
   try
      i := 0;
      for idx := 0 to ComponentCount-1 do
       if (Components[idx] is TImage) then
       begin
          ImageList.GetBitmap(i,bmp);
          (Components[idx] as TImage).Picture.Assign(bmp);
          Inc(i);
       end;
   finally
     bmp.Free;
   end;
end;

Thanks alot

Though I do not have the documentation (Lazarus). Also I never understood what you meant before until I read this. I understand now. Thanks. All my attempts ended in a SigSegv error, perhaps i should have bought that up.

Almost all that is written for Delphi important for Lazarus. Because search for information for dolphins if you can not find Lazarus.
I'm trying to say that you are using an array in vain for the TImage. If you lozhish component on the form, the form is aware of this component. Accordingly, we can use it (see property Components [] and Controls []). These properties are available for all window components. The only thing you have used two-dimensional array, and these properties - a linear list. This is not a problem, you can always calculate the row and column in a linear array, knowing the width and height of the matrix.
In addition, instead of the array is much more convenient to use the class TObjectList.

There is no time, but later I'll show an example of how you can use these properties to emulate the array. I think many students at this site will be useful. I myself have not a student.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.