读书人

初学Delphi第一章的有关问题

发布时间: 2012-03-17 19:06:28 作者: rapoo

初学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);

读书人网 >.NET

热点推荐