如何将字符串分配给整数?
How to assign string to integer?
现在是代码:
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;
当我写 k:=Edit1.Text
选项时甚至不建议使用。有人有解决方案吗?
您正在尝试将声明为整数的 'k' 设置为来自 Edit1.Text
的字符串
使用 StrToInt 将 Edit1.Text 转换为整数,然后重试。顺便说一句,消息:"Incompatabile types: 'Integer' and 'TCaption'" 就是这个意思。不兼容。
现在是代码:
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;
当我写 k:=Edit1.Text
选项时甚至不建议使用。有人有解决方案吗?
您正在尝试将声明为整数的 'k' 设置为来自 Edit1.Text
的字符串使用 StrToInt 将 Edit1.Text 转换为整数,然后重试。顺便说一句,消息:"Incompatabile types: 'Integer' and 'TCaption'" 就是这个意思。不兼容。