Search code examples
delphidelphi-7

How to assign string to integer?


Here is the code now:

procedure TForm1.Button1Click(Sender: TObject);
var j,r:integer; k:string;
begin
  k := Edit1.Text;

  if StrToInt(k) > 0 then 
    if StrToInt(k)<10 then
      r := StrToInt(k);
  if StrToInt(k) = 10 then
    r := 1;
  if StrToInt(k) > 10 then 
    if StrToInt(k) < 190 then
      j:=StrToInt(k) mod 10;
  r := j-1;

  ShowMessage('Na toj poziciji se nalazi: '+ IntToStr(r));
end;

When I write k:=Edit1.Text option is not even suggested to use. Anybody got a solution?


Solution

  • you are trying to set 'k', which is declared an integer, to a string from Edit1.Text

    Convert Edit1.Text to an integer using StrToInt and try it again. BTW the message: "Incompatabile types: 'Integer' and 'TCaption'" means exactly that. It's incompatible.