Показать сообщение отдельно
  #3  
Старый 20.11.2010, 19:13
iluxa1810 iluxa1810 вне форума
Новичок
 
Регистрация: 06.10.2010
Сообщения: 51
Репутация: 10
По умолчанию

Меня интересует ,как читается эта строка else if not Provinputint(key) then key:=chr(0); и за как осуществляется работа функции в If.
Я просто немного алгоритм этот понять не могу

Код:
function Provinputint (ch:char):boolean;
begin
  If (ch>='0') and (ch<='9') or (ch=#13) or (ch=#8)
  then Provinputint:=True
  else Provinputint:=false;
  end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then edt2.SetFocus
else if not Provinputint(key) then key:=chr(0);
end;

procedure TForm1.edt2KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then  btn1.SetFocus
else if not Provinputint(Key) then key:=chr(0);
end;

procedure TForm1.btn1Click(Sender: TObject);
var
  n,m:Integer;
  coch:longint;
  function fact(k:integer):longint;
  var
    i:Integer;
    res:longint;
begin
 if k=0 then fact:=1 else
 begin
   res:=1;
   for i:=1 to k do res:=res*i;
   fact:=res;

 end;

end;
begin
  if (edt1.Text='') or (edt2.Text='') then
  ShowMessage('Введены не все данные')
  else
  begin
    n:=StrToInt(edt1.Text);
    m:=StrToInt(edt2.text);
    coch:=fact(n) div (fact(m)*fact(n-m));
    lbl1.caption:='Число сочетаний = '+ FloatToStr(coch);
  end;

end;
end.
Ответить с цитированием