943,682 Members | Top Members by Rank

Ad:
Dec 13th, 2008
0

extended to integer

Expand Post »
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

Pascal and Delphi Syntax (Toggle Plain Text)
  1. form2.Image1.BringToFront;
  2. form2.Image1.Picture.LoadFromFile(edit1.Text); {Load the picture from the destination in edit1}
  3.  
  4. if form9.RadioButton1.Checked = true then {If stretxh is true then}
  5.  
  6. begin
  7.  
  8. form2.Image1.Stretch := true;
  9.  
  10. end
  11.  
  12. else {if stretch isn true}
  13.  
  14. begin
  15.  
  16. form2.Image1.Stretch := false;
  17.  
  18. if form9.RadioButton2.Checked = true then {IF resize large images = true}
  19. begin
  20.  
  21. if form2.Image1.Picture.Height > screen.Height then {if the picture is bigger then screen}
  22. begin
  23.  
  24. imageheightdiff := Trunc(form2.Image1.Picture.Height)- Trunc(screen.Height);
  25. 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}
  26. form2.image1.picture.height := imageprocent * 100 / Round(form2.Image1.Picture.Height);
  27. form2.image1.picture.width := imageprocent * 100 / Round(form2.Image1.Width);
  28.  
  29. end
  30.  
  31. end;
  32. end;

imageheightdiff & imageprocent is both integer variables

i hope someone can give me an answer cause i simple cant understand what im doing wrong...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Dec 13th, 2008
0

Re: extended to integer

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);
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Dec 13th, 2008
0

Re: extended to integer

You could also have just used div - as div is for integer devision
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: can you help me - 2D array
Next Thread in Pascal and Delphi Forum Timeline: im lost





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC