Im trying to make a screensaver whit the option to support single and multiple images. this is the code for single images where im trying to make it fit large images to screen but no matter what of these conversion types ive used

Round Rounds a floating point number to an integer
Trunc The integer part of a floating point number

it crashes whit - Incomplete types "Integer" and "Extended"

and then im wondering if its because im yousing delphi 2009 .. maybe i should bye the 2005 if thats still possible.

this is how my code looks

form2.Image1.BringToFront; 
              form2.Image1.Picture.LoadFromFile(edit1.Text); {Load the picture from the destination in edit1}

              if form9.RadioButton1.Checked = true then {If stretxh is true then}

                begin

                  form2.Image1.Stretch := true;

                end

              else	{if stretch isn true}

                begin

                  form2.Image1.Stretch := false;

                  if form9.RadioButton2.Checked = true then {IF resize large images = true}
                    begin

                      if form2.Image1.Picture.Height > screen.Height then {if the picture is bigger then screen} 
                        begin

                          imageheightdiff := Trunc(form2.Image1.Picture.Height)- Trunc(screen.Height);
                          imageprocent := imageheight * Trunc(form2.Image1.Picture.height) / 100 ; {here it crashes and says Integer and extended - like if it havent been convertet to int above}
                          form2.image1.picture.height := imageprocent * 100 / Round(form2.Image1.Picture.Height);
                          form2.image1.picture.width  := imageprocent * 100 / Round(form2.Image1.Width);

                        end

                    end;
                end;

imageheightdiff & imageprocent is both integer variables

i hope someone can give me an answer cause i simple cant understand what im doing wrong...

i found the answer elsewhere

here it is...

imageheightdiff := Trunc(form2.Image1.Picture.Height)- Trunc(screen.Height);
here you don't have to use trunc function as Height is an integer property

imageprocent := imageheight * Trunc(form2.Image1.Picture.height) / 100 ; {here it crashes and says Integer and extended - like if it havent been convertet to int above}
The problem comes from the divide by 100 which gives a non integer result.
You could put form2.Image1.Picture.height/100 in trunc parenthesis, you would get the nearest integer just below.
If you use Round function, you will get the nearest integer:
imageprocent := imageheight * Round(form2.Image1.Picture.height / 100) ;
And if you want more precision, it is better to include the multiply inside the Round parenthesis:
imageprocent := Round(imageheight * form2.Image1.Picture.height / 100) ;

form2.image1.picture.height := imageprocent * 100 / Round(form2.Image1.Picture.Height);
form2.image1.picture.width := imageprocent * 100 / Round(form2.Image1.Width);
Use Round for the whole expression in both instructions:
form2.image1.picture.height := Round(imageprocent * 100 /form2.Image1.Picture.Height);
form2.image1.picture.width := Round(imageprocent * 100 / form2.Image1.Width);

This article has been dead for over six months. Start a new discussion instead.