Board index » delphi » Drawing to many TImages in turn

Drawing to many TImages in turn

Hi All,

My problem is this:

I have an array of "images" (actually the instructions to draw the images)
and i wish to draw each one to its own TImage in a way equivalent to

for Ndx := 0 to ... do

Image0.Canvas  := Array[0]
Image1.Canvas := Array[1]
...etc

 Is this possible - can i "point"  to each TImage component by some kind of
counter, like i would use to index the array, and hence keep confusion to a
minimum.

Regards

PX

 

Re:Drawing to many TImages in turn


In article <88a6l6$bq...@lure.pipex.net>, "Patrick Robinson"

Quote
<mak...@dial.pipex.com> writes:
>My problem is this:

>I have an array of "images" (actually the instructions to draw the images)
>and i wish to draw each one to its own TImage in a way equivalent to

>for Ndx := 0 to ... do

>Image0.Canvas  := Array[0]
>Image1.Canvas := Array[1]
>...etc

I'm not quite sure if I understand what your problem is but you can create the
TImages in an array and then reference them as you would any other array. You
need to create them and set propertys at run time of course but it does mean
you can create them _only_ if you need them and free them as (not!) required.
An array of TImage is just an array of pointers until they've been created so
even if you declare a quite big array it still isn't going to take up much
memory. If they are all the same regarding propertys then derive a new TImage
and set the default propertys to whatever you want and create an array of
TYourImage instead.

type
  TImageArray = array[0..Wahtever] of TImage;

var
  ImageArray: TImageArray;

Once you've created them just access them as you would any other array. You
could use a TList instead of an array which would allow you to easily move add
and insert but personally I don't like all the type casting you have to do with
TLists but it's just my preference.

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V equation editor
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Drawing to many TImages in turn


Im Artikel <20000215041144.16165.00000...@nso-bj.aol.com>, gwhit41...@aol.com
(Gordon Whittam) schreibt:

Quote
>You need to create them and set propertys at run time

I have a similar problem, and would like to initialize the images from some
bitmap resource. But how to create and add bitmap resources to a unit?

DoDi

Re:Drawing to many TImages in turn


VBDis skrev i meldingen
<20000215085649.02091.00000...@nso-fa.aol.com>...
Quote
>Im Artikel <20000215041144.16165.00000...@nso-bj.aol.com>,

gwhit41...@aol.com

Quote
>(Gordon Whittam) schreibt:

>>You need to create them and set propertys at run time

>I have a similar problem, and would like to initialize the images from
some
>bitmap resource. But how to create and add bitmap resources to a unit?

1) I've seen components for storing files as part of a project (using
the .dfm format)
2) If you're on NT, you may add resources to an existing .dll or .exe
using UpdateResource() API.
3) TImageList...

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Drawing to many TImages in turn


In article <20000215085649.02091.00000...@nso-fa.aol.com>, vb...@aol.com

Quote
(VBDis) writes:
>>You need to create them and set propertys at run time

>I have a similar problem, and would like to initialize the images from some
>bitmap resource. But how to create and add bitmap resources to a unit?

>DoDi

I've just tried this which seems to work Ok but I'm making no claims for it!

The resource (Bitmaps.res) was created in the image editor, leaving the names
as the default. There were 5 in this case, created with a number on each, 1..5.
Personally I'd save and load them from a stream, but...

Gordon

const
    MaxImages = 1000;
type
  TMyImage = class(TImage)
  public
    constructor create(aOwner: TComponent);override;
  end;

  TImageArray = array[0..MaxImages-1] of TMyImage;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
//if you are using D5 or maybe D4 you could use a dynamic array
// type TImageArray = array of TMyImage;
//and then set the length in each iteration in create
  ImageArray: TImageArray;

implementation

{$R *.DFM}
{$R Bitmaps.Res}

constructor TMyImage.create(aOwner: TComponent);
begin
inherited create(aOwner);
Autosize:= true;
Stretch:= false;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
  L: integer;
begin
  i:= 0;
  L:= 0;
while i < high(TImageArray) do
  begin
   ImageArray[i]:= TMyImage.Create(self);
      try
         ImageArray[i].Picture.Bitmap.LoadFromResourceName(HINSTANCE,
               'BITMAP'+intToStr(i+1));
      except
        on EResNotFound do
          begin
             ImageArray[i].free; //this wasn't in when I tried it but it gets
created
                                         //before the attempt to load resource
             break;
         end;
        end;
//it won't get this far if except gets executed
   ImageArray[i].Parent:=form1;
   ImageArray[i].left:= L;
   L:= L+ ImageArray[i].Width +1;
    inc(i);
    end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V equation editor
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Drawing to many TImages in turn


Im Artikel <Rbeq4.292$Po1.4...@news1.online.no>, "Bj?rge S?ther"
<REMOVE_bsaet...@online.no> schreibt:

Quote
>3) TImageList...

This is what I'm currently using, and then I steal the bitmaps from that
object. But what if another project does NOT include that form?

Clarification: My problem arises from a non-form unit, which does not normally
have resources :-(

DoDi

Other Threads