Recent

Author Topic: [SOLVED] ProgressBar Help  (Read 10098 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
[SOLVED] ProgressBar Help
« on: October 21, 2013, 07:32:44 pm »
Hi to all, I am stuck at ProgressBar control, While setting the Max value of ProgressBar control i had found that it only takes integer, where as i had to feed it some qword parts. How to acheive this with traditional widows progressbar control/ BGRAFlashProgressbar control.
« Last Edit: October 23, 2013, 06:21:56 am by deepaak99 »
Holiday season is online now. :-)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: ProgressBar Help
« Reply #1 on: October 21, 2013, 08:33:36 pm »
Could not you round them?

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: ProgressBar Help
« Reply #2 on: October 21, 2013, 08:41:23 pm »
Could not you round them?

no rounding does not solve my problem, i am currently using this method, is this method correct or have to implement something else ,
QWord values cannot be set in progressbar.max, because it is integer, so, used this method to calculate the percentage of done/totalbytes.

Code: [Select]
percent := Trunc((doneBytes/totalbytes) * 100);
« Last Edit: October 21, 2013, 08:43:38 pm by deepaak99 »
Holiday season is online now. :-)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: ProgressBar Help
« Reply #3 on: October 21, 2013, 11:02:59 pm »
No, probably you need to set this value to Position property and total bytes to Max.

sam707

  • Guest
Re: ProgressBar Help
« Reply #4 on: October 22, 2013, 01:10:31 am »
can't you write a function like that ?

function progresspos( positon, limit: double) : integer;
begin
  result:= Integer (position / limit * 100) ; // got a percentage
end;

.. seting maximum progressbar to 99 (0 to 99% = 100)

... bla bla

  ProgressBar.Position := progresspos (mybignum, mybiglimit);

...

I always did it that way, even if I need a tooltip or a TLabel on one side to show exact values, otherwise I'm afraid screens won't be large enough to count 'QWord' pixels on any axis lol... just saying
« Last Edit: October 22, 2013, 01:48:02 am by sam707 »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: ProgressBar Help
« Reply #5 on: October 22, 2013, 01:17:28 am »
Your code is fine  :). I prefer using div instead:

Code: [Select]
var
  percent: Integer;
...
percent := (doneBytes  * 100) div totalBytes;

In case there were smooth progress bars -not sure they exist-, I might consider using its width as the maximum value instead of 100, like this:

Code: [Select]
var
   doneBytes, totalBytes, qwPos: QWord;
   someMaxValue: Integer;
...
  someMaxValue := YourProgressBar.Width;
  YourProgressBar.Max := someMaxValue;
...
  YourProgressBar.Position := (doneBytes * someMaxValue) div totalBytes;

Again, that's just what I prefer!!

sam707

  • Guest
Re: ProgressBar Help
« Reply #6 on: October 22, 2013, 01:36:42 am »
Div may not work if you divide before multiply, it returns an Integer result, I need a percentage that is a Real.

that is why my arguments are 'Double' (could be Float), unsing implicit transtypage from QWord
« Last Edit: October 22, 2013, 01:44:54 am by sam707 »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: ProgressBar Help
« Reply #7 on: October 22, 2013, 02:19:47 am »
Div may not work if you divide before multiply, it returns an Integer result, I need a percentage that is a Real.

that is why my arguments are 'Double' (could be Float), unsing implicit transtypage from QWord

I meant deepaak99, but your code is fine as well, sam707. I'm not sure why you need percentage if you plan to use it with ProgressBar.Position which is of type Integer. As for the order of division and multiplication, you are right it will NOT work if you divide before you multiply. That's why I have brackets. I anticipate a possible problem when totalBytes exceeds $7FFFFFFFFFFFFF (these are seven bytes).  :)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: ProgressBar Help
« Reply #8 on: October 22, 2013, 06:51:59 am »
No, probably you need to set this value to Position property and total bytes to Max.


No, Total bytes to Max cannot be set. Because TProgressBar.Max (Integer) whereas, Total Bytes can be QWord value.

I had not faced this issue in Visual Basic/ C++, Because there one can set the Max value to Unsigned int64 equivalent to QWord in Pascal.
Holiday season is online now. :-)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: ProgressBar Help
« Reply #9 on: October 22, 2013, 07:02:17 am »
Code: [Select]
Operator Operation Operands Result
------------------------------------------------------------------------------------------
/ | Real division | real or integer | real
div | Integer division | integer | integer

Div is division in which the fractional part (remainder) is discarded. It means the integer part of the result of dividing two integers.

div and mod only work on integers. / works on both reals and integers but will always yield a real answer. The other operations work on both reals and integers. When mixing integers and reals, the result will always be a real since data loss would result otherwise. This is why Pascal uses two different operations for division and integer division.

Code: [Select]
7 / 2 = 3.5 (real), but 7 div 2 = 3 (and 7 mod 2 = 1 since that's the remainder).
according to the above logic i had used this method.

Code: [Select]
percent := Trunc((doneBytes/totalbytes) * 100);
Div failed in this scenario
Quote
5/10 results 0.5 where div output the result as 0, because only integer part is returned discarding the fractional part, and when 0 is multiplied by 100 then the result is 0, so the progress percentage for 5 / 10 = 0% which is completely wrong.
Holiday season is online now. :-)

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: ProgressBar Help
« Reply #10 on: October 22, 2013, 03:37:40 pm »
Thank you deepaak99 for the detailed explanation. It makes the difference between div and / very clear.

according to the above logic i had used this method.

Code: [Select]
percent := Trunc((doneBytes/totalbytes) * 100);
Div failed in this scenario

It seems that you missed what sam707 had said  ;D

Div may not work if you divide before multiply,

And I agreed with him

As for the order of division and multiplication, you are right it will NOT work if you divide before you multiply. That's why I have brackets.

Unless you have some other reasons, you might want to try:

Code: [Select]
  percent := (doneBytes * 100) div totalbytes;

In this case you don't need to use Trunc nor floating point division and multiplication. Again, this is just a preference issue, mainly.

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: ProgressBar Help
« Reply #11 on: October 23, 2013, 06:20:49 am »




It seems that you missed what sam707 had said  ;D

Div may not work if you divide before multiply,

And I agreed with him

As for the order of division and multiplication, you are right it will NOT work if you divide before you multiply. That's why I have brackets.

Unless you have some other reasons, you might want to try:

Code: [Select]
  percent := (doneBytes * 100) div totalbytes;

In this case you don't need to use Trunc nor floating point division and multiplication. Again, this is just a preference issue, mainly.

Firstly thanks to @sam707 and you for clarifying this confusion. In mathematics this term is called B.O.D.M.A.S which stood for Brackets, Orders, Division, Multiplication, Addition, Subtraction.

I had accepted @sam707 method, because it is more correct and accrual method for this condition. Thank you every one for their suggestions. 
Holiday season is online now. :-)

 

TinyPortal © 2005-2018