Algorithm Math Delphi

function BinToDec(i:String):integer;
var
sonuc,k,z,katsayi:integer;
begin
katsayi:=1;
sonuc:=0;
For k:=length(i) downto 1 do
begin
z:=strtoint(i[k]);
sonuc:=sonuc+ (z * katsayi);
katsayi:=katsayi*2
end;
BinToDec:=Sonuc;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Text:=inttostr(BintoDec(edit1.text));
end;