Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > extended problem


Автор: huismori 29.3.2010, 16:33
i am trying to show image for rates but it doesnt always show the correct image... i dont know what i am doing wrong !!!

Код

var
      ini:TInifile; 
      euro, alis:extended;     
begin
      ini := TINIFile.Create(ExtractFilePath(Application.ExeName)+'Rates.INI ');
      euro:= ini.ReadFloat('Rate1','EURO', 2.1150);  
      alis:= ini.ReadFloat('Rate2','EURO', 2.1150);   
      ini.free;
      if alis < euro then
      Edit1.RightImageIndex:=14 else
      if alis = euro then
      Edit1.RightImageIndex:=13 else
      if alis > euro then
      Edit1.RightImageIndex:=12 ;
end;

Автор: Keeper89 29.3.2010, 19:33
Код

uses
  Math;

const
  VALUE_FIX = 0.001;

var
  ini:TInifile; 
  euro, alis:extended;
  compareResult: (-1..1);    
begin

  ini := TINIFile.Create(ExtractFilePath(Application.ExeName)+'Rates.INI ');
  try
    euro:= ini.ReadFloat('Rate1','EURO', 2.1150);  
    alis:= ini.ReadFloat('Rate2','EURO', 2.1150);   
  finally
    ini.free;
  end;

  compareResult := Math.CompareValue(alis, euro, VALUE_FIX);

  if compareResult = -1 then
    Edit1.RightImageIndex:=14
  else if compareResult = 0 then
    Edit1.RightImageIndex:=13
  else
    Edit1.RightImageIndex:=12;
end;

Автор: huismori 30.3.2010, 08:53
thanks keeper but i got this error;
Код

compareResult: (-1..1);

identifier expected but '-' found

Автор: bems 30.3.2010, 15:55
Keeper89, квадратные скобки же

Автор: Keeper89 31.3.2010, 23:54
Цитата(bems @  30.3.2010,  15:55 Найти цитируемый пост)
Keeper89, квадратные скобки же 

Мой косяк, лучше даже так:
Код

uses
  Math, Types;

const
  VALUE_FIX = 0.001;

var
  ini:TInifile; 
  euro, alis:extended;

begin
  ini := TINIFile.Create(ExtractFilePath(Application.ExeName)+'Rates.INI ');
  try
    euro:= ini.ReadFloat('Rate1','EURO', 2.1150);  
    alis:= ini.ReadFloat('Rate2','EURO', 2.1150);   
  finally
    ini.free;
  end;

  case Math.CompareValue(alis, euro, VALUE_FIX) of
    LessThanValue:
        Edit1.RightImageIndex := 14;
    EqualsValue:
        Edit1.RightImageIndex := 13;
    GreaterThanValue:
        Edit1.RightImageIndex := 12;
  end;
end;

Автор: muratboy31 2.4.2010, 14:50
really good trick keeper  smile 

Автор: huismori 2.4.2010, 15:15
when i use it like that i get an error

Код

   case Math.CompareValue(alisex, euro30, VALUE_FIX) of
    LessThanValue:
        tl5.RightImageIndex := 14;
        tl4.RightImageIndex := 14;
    EqualsValue:
        tl5.RightImageIndex := 13;
        tl4.RightImageIndex := 13;
    GreaterThanValue:
        tl5.RightImageIndex := 12;
        tl4.RightImageIndex := 12;
   end;


Цитата

Constant expression expected.

Автор: Keeper89 2.4.2010, 15:29
Цитата(huismori @  2.4.2010,  15:15 Найти цитируемый пост)
when i use it like that i get an error

Код

case Math.CompareValue(alisex, euro30, VALUE_FIX) of
    LessThanValue:
        begin
            tl5.RightImageIndex := 14;
            tl4.RightImageIndex := 14;
        end;
    EqualsValue:
        begin
            tl5.RightImageIndex := 13;
            tl4.RightImageIndex := 13;
        end;
    GreaterThanValue:
        begin
            tl5.RightImageIndex := 12;
            tl4.RightImageIndex := 12;
        end;
end;

Автор: huismori 2.4.2010, 15:34
i love u keeper smile 
thanks alot

another question how would i calculate percantage... from alisex to euro... for example ;

-%0,10   when it less
or
+%0,5    when it is more

Автор: Keeper89 2.4.2010, 15:47
Код

uses
  Math, Types;
  
const
  VALUE_FIX = 0.001;
  
var
  ini:TInifile; 
  euro, alisex: extended;
  
begin
  ini := TINIFile.Create(ExtractFilePath(Application.ExeName)+'Rates.INI ');
  try
    euro:= ini.ReadFloat('Rate1','EURO', 2.1150);  
    alisex:= ini.ReadFloat('Rate2','EURO', 2.1150);   
  finally
    ini.free;
  end;
  
    case Math.CompareValue(alisex, euro30, VALUE_FIX) of
    LessThanValue:
        begin
            tl5.RightImageIndex := 14;
            tl4.RightImageIndex := 14;
            Showmessage(Format('-%.2f', [(euro30 - alisex) / 100]));
        end;
    EqualsValue:
        begin
            tl5.RightImageIndex := 13;
            tl4.RightImageIndex := 13;
        end;
    GreaterThanValue:
        begin
            tl5.RightImageIndex := 12;
            tl4.RightImageIndex := 12;
            Showmessage(Format('+%.2f', [(alisex - euro30) / 100]));
        end;
end;
end;

Автор: huismori 2.4.2010, 15:59
it always show  -0.00  or +0.00    like that ... no % and correct percentage...

Автор: Keeper89 2.4.2010, 16:05
Then your values are to small, try to use
Код

'%f'

instead of
Код

'%.2f'

Автор: huismori 2.4.2010, 16:08
now it is  -0  or  +0       still not correct value...

Автор: Keeper89 2.4.2010, 16:50
Try
Код

'%g'

instead of
Цитата(Keeper89 @  2.4.2010,  16:05 Найти цитируемый пост)
    
'%f'


Автор: huismori 5.4.2010, 10:28
thanks keeper that worked i think but is there anyway to make it shorter because it show sooo many numbers

user posted image

it would b enough if it show last 3 digits or 4...

example :  - 0,011  or  0,0112

Автор: Keeper89 5.4.2010, 11:30
You should define how many symbols your result has (or just use '%.3f' or '%.4f'), otherwise you'll get 0 as it was smile

See Format function syntax http://www.delphibasics.co.uk/RTL.asp?Name=Format.

Автор: huismori 5.4.2010, 11:44
thanks keeper  smile 

Автор: huismori 12.4.2010, 14:24
solved it...
i think i am going blind smile

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)