I have this function 'bintoint' which I use to convert binary number to decimal:
function bintoint(var n: string):integer;
var i: integer;
Begin
result:= 0;
Trim(n);
for i:=length(n) downto 1 do
result := result + (strtoint(n[i])*(potencia(2,i-1))); {Here's the source for the error, at the last 'i'}
End;
It shows a error at the i, which is the variable of the 'for' loop, declared at 'var' section. 'potencia' is another function I placed above that replaces the 'power(base,exp)' so I can calculate power with integer numbers.
function potencia(var base,exp: integer):integer;
I have seen various similar questions on the site, but their errors appear from variables at the parameters of the procedure/function and not at the variables section.
Will appreciate if you could advise me with this problem.
Thanks in advance.
potencia
function, not constants. Or, if you're not changingbase
norexp
parameters inside that function, just remove thevar
from its definition. – TLamaconst
in the function. – LU RDTrim
is a function that returns a new string, not a procedure that edits in place the string passed to it. As such, either just drop thevar
and don := Trim(n)
, or replace it withconst
and add a new local string variable that you then assign theTrim
call to. – Chris Rolliston