Board index » delphi » typecasting question

typecasting question

I am executing a graphics loop where i need to assign a variable (pic1,
pic2, pic3 and so on) to the picX part of picX.loadFromStream(stream)

The loop would work like :

1st time:

for i := 1 to 100 do
pic1.loadFromStream(stream)
end;

2nd time : pic2.loadFromStream(stream)
3rd time : pic3.loadFromStream(stream)

How do you substitute pic1 - picX in the loop with a variable where i
defines the 1,2,3 in the different picX?

pic1 - picX are Tbitmap's which have been initialized properly with:

pic1 : Tbitmap;
pic1 : Tbitmap.create;

Thanks in advance!

Anders

(to reply by mail, remove the three xxx)

 

Re:typecasting question


Quote
>I am executing a graphics loop where i need to assign a variable (pic1,
>pic2, pic3 and so on) to the picX part of picX.loadFromStream(stream)

>The loop would work like :

>1st time:

>for i := 1 to 100 do
>pic1.loadFromStream(stream)
>end;

>2nd time : pic2.loadFromStream(stream)
>3rd time : pic3.loadFromStream(stream)

>How do you substitute pic1 - picX in the loop with a variable where i
>defines the 1,2,3 in the different picX?

>pic1 - picX are Tbitmap's which have been initialized properly with:

>pic1 : Tbitmap;
>pic1 : Tbitmap.create;

Just create all your pic and store them into a TList component !

--- In form create (for example)
mylist := TList.Create;
for i := 1 to 100 do
  MyList.Add( TBitmap.create );

--- when you want to apply load to all TBitmap do this
for i := 0 to MyList.Count-1 do
  TBitmap( MyList.Item[i] ).LoadFromStream( MyOpenedStream );

--- When you close your form, destroy the list & the bitmaps
while MyList.Count>0 do begin
  TBitmap( MyList.Items[i] ).Free;
  MyList.Delete(0);
end;

Other Threads