SRL Archive - OSR Help

Change picture in form


tom99

2010-03-01 03:39:04

Procedure OnTimer2(Sender: TObject);
var
i2: integer;
Images: Array [0..3] Of TImage;
b2, w2, h2,curbanner: Integer;
begin
For I2 := 0 To 1 Do
Begin
Images[I2] := TImage.Create(FrmDesign);
Images[I2].Parent := FrmDesign;

Case CurBanner Of // See*
0: b2 := loadbitmap(AppPath + 'portal1.bmp');
1: b2 := loadbitmap(AppPath + 'portal3.bmp');
2: b2 := loadbitmap(AppPath + 'portal6.bmp');
3: b2 := loadbitmap(AppPath + 'portal7.bmp');
End;
getbitmapsize(b2, w2, h2);
copycanvas(getbitmapcanvas(b2), Images[1].canvas, 0, 0,
w2, h2, 0, 0, w2, h2);
CurBanner := CurBanner + 1; //
If CurBanner > 3 Then CurBanner := 0; //
End;

end;

//code witch execute the procedure
Timer2 := TTimer.Create(FrmDesign);
Timer2.Interval := 2000;
Timer2.OnTimer := @OnTimer2;
Timer2.Enabled := True;

//What is wrong with this code? i dont see the error but when i try to run it scar crashes [Runtime Error] : Out Of Range in line 246 in script
//I want an fancy modern animating form :( somone help plz

YoHoJo

2010-03-01 04:30:28

Entire script would help more.
And put
tags around your code (did it for you)

Frement

2010-03-01 04:45:18

I think it would be better if you would load them before that function. I can imagine it would lag when its loading them so fast, add some Wait in there, like 5ms or something. Or how fast is the timer?

MasterKill

2010-03-01 04:58:39

I replied in a pm to him, he needs to switch the images with a timer, not after declaring the images. He is following my tutorials but I think he just missed some lines.

Good luck Tom.

tom99

2010-03-01 05:14:32

From: MasterKill
I replied in a pm to him, he needs to switch the images with a timer, not after declaring the images. He is following my tutorials but I think he just missed some lines.

Good luck Tom.



This display one picture, wont change to another, or does it but to fast? i can only see one picture on the form.

Procedure OnTimer2(Sender: TObject);
var
i: integer;
Images: Array [0..3] Of TImage;
b2, w2, h2: Integer;
begin
For I := 0 To 1 Do
Begin
Images[I] := TImage.Create(FrmDesign);
Images[I].Parent := FrmDesign;
Case I Of
0: Begin
Images[I].Width := 128;
Images[I].Height := 128;
Images[I].Left := 515;
Images[I].Top := 210;
b2 := loadbitmap(AppPath + 'portal1.bmp');
getbitmapsize(b2, w2, h2);
copycanvas(getbitmapcanvas(b2), Images[I].canvas, 0, 0, w2,
h2, 0, 0, w2, h2);
End;
1: Begin
Images[I].Width := 128;
Images[I].Height := 128;
Images[I].Left := 515;
Images[I].Top := 210;
b2 := loadbitmap(AppPath + 'portal3.bmp');
getbitmapsize(b2, w2, h2);
copycanvas(getbitmapcanvas(b2), Images[I].canvas, 0, 0, w2,
h2, 0, 0, w2, h2);
End;
2: Begin
Images[I].Width := 128;
Images[I].Height := 128;
Images[I].Left := 515;
Images[I].Top := 210;
b2 := loadbitmap(AppPath + 'portal6.bmp');
getbitmapsize(b2, w2, h2);
copycanvas(getbitmapcanvas(b2), Images[I].canvas, 0, 0, w2,
h2, 0, 0, w2, h2);
End;
3: Begin
Images[I].Width := 128;
Images[I].Height := 128;
Images[I].Left := 515;
Images[I].Top := 210;
b2 := loadbitmap(AppPath + 'portal7.bmp');
getbitmapsize(b2, w2, h2);
copycanvas(getbitmapcanvas(b2), Images[I].canvas, 0, 0, w2,
h2, 0, 0, w2, h2);
I:=0;
end;
end;
end;
end;

The picture i can see is portal3 i find it very strange its not portal 1 or portal 7 since that is first/last to be loaded.

if i change this
For I2 := 0 To 1 Do
to this
For I2 := 0 To 2 Do
then it loads portal 6 instead but
if i change it to For I2 := 0 To 3 Do
then scar crashes.

MasterKill

2010-03-01 05:45:13

You do not want to create the TImage on the timers loop.

First define your default image in the forum setup, then you can change the image it's content (without creating the full image again) with the timer.

Timer function content:

Case CurBanner Of
0: b := loadbitmap(AppPath + 'MKFormTut\pcbanner.bmp');
1: b := loadbitmap(AppPath + 'MKFormTut\srlbanner.bmp');
2: b := loadbitmap(AppPath + 'MKFormTut\ownbanner.bmp');
3: b := loadbitmap(AppPath + 'MKFormTut\formbanner.bmp');
End;
getbitmapsize(b, w, h);
copycanvas(getbitmapcanvas(b), Images[1].canvas, 0, 0,
w, h, 0, 0, w, h); // this changes the current banners image content, with the loaded image in the case
CurBanner := CurBanner + 1;
If CurBanner > 3 Then CurBanner := 0;

As you can see the code above doesn't remake the image, but just changes its content.

E: For the record; The changing banner image only takes 1 TImage.