Results 1 to 6 of 6

Thread: Change picture in form

  1. #1
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Unhappy Change picture in form

    SCAR Code:
    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;
    SCAR Code:
    //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
    Last edited by tom99; 03-01-2010 at 09:48 AM. Reason: Bether explarnation

  2. #2
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

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

  3. #3
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    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?
    There used to be something meaningful here.

  4. #4
    Join Date
    May 2007
    Location
    Netherlands, Amersfoort
    Posts
    2,701
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  5. #5
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by MasterKill View Post
    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.
    SCAR Code:
    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.
    Last edited by tom99; 03-01-2010 at 10:28 AM.

  6. #6
    Join Date
    May 2007
    Location
    Netherlands, Amersfoort
    Posts
    2,701
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    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:
    SCAR Code:
    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.
    Last edited by MasterKill; 03-01-2010 at 10:49 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •