首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

初学Delphi第一章的有关问题

2012-03-17 
初学Delphi第一章的问题是一个类似计算器的东西为什么用integer声明变量就出错呢?代码如下:unitUnit1inte

初学Delphi第一章的问题
是一个类似计算器的东西   为什么用integer声明变量就出错呢?代码如下:
unit   Unit1;

interface

uses
    Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
    Dialogs,   StdCtrls;

type
    TForm1   =   class(TForm)
        Label1:   TLabel;
        Label2:   TLabel;
        Edit1:   TEdit;
        Edit2:   TEdit;
        Edit3:   TEdit;
        Label3:   TLabel;
        Button1:   TButton;
        Button2:   TButton;
        procedure   Button1Click(Sender:   TObject);
    private
        {   Private   declarations   }
    public
        {   Public   declarations   }
    end;

var
    Form1:   TForm1;


implementation

{$R   *.dfm}

procedure   TForm1.Button1Click(Sender:   TObject);
var
    num1:   Integer;
    num2:   Integer;
    num3:   Integer;
begin
num1:=   edit1.Text;
num2:=   edit2.Text;
num3:=   num1+num2;
edit3.Text:=num3;
end;

end.


在线等谢谢了

[解决办法]
类型不匹配,需要进行类型转换
num1(integer类型):= edit1.Text(字符串类型);

num1:= strtointdef(edit1.Text,0);
....

edit3.Text:=inttostr(num3);

热点排行