extended to integer

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 17
Reputation: darkyere is an unknown quantity at this point 
Solved Threads: 0
darkyere darkyere is offline Offline
Newbie Poster

extended to integer

 
0
  #1
Dec 13th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: darkyere is an unknown quantity at this point 
Solved Threads: 0
darkyere darkyere is offline Offline
Newbie Poster

Re: extended to integer

 
0
  #2
Dec 13th, 2008
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);
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: extended to integer

 
0
  #3
Dec 13th, 2008
You could also have just used div - as div is for integer devision
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC