type
TForm2 = class(TForm)
first: TEdit;
second: TEdit;
Button1: TButton;
third: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
procedure TForm2.Button1Click(Sender: TObject);
var
first:integer;
second:integer;
third:integer;
begin
third:=first+second;
end;
end.
uj5u.com熱心網友回復:
third.text:=inttostr(strtointdef(first.text,0)+strtointdef(second.text,0));
uj5u.com熱心網友回復:
你這樣定義的變數和Edit名字相同,不感覺很復雜嗎?uj5u.com熱心網友回復:
looks like doesn't help!
uj5u.com熱心網友回復:
first,second and third already change property to integer,. why still have to use so many code?
uj5u.com熱心網友回復:
procedure TForm2.Button1Click(Sender: TObject);begin
third.text:=inttostr(strtointdef(first.text,0)+strtointdef(second.text,0));
end;
uj5u.com熱心網友回復:
you'd better use Delphi 6 to begin your study. Because in Delphi6 you can search for every functions and procedures helps,just press F1 for help.it is the fast way for your study ,just try ituj5u.com熱心網友回復:
procedure TForm2.Button1Click(Sender: TObject);
var
//最好能讓變數和控制元件名稱有所區別,方便自己和他人閱讀程式,增加程式的可讀性
n_first:integer;
n_second:integer;
n_third:integer;
begin
//可以這樣做
//先把first Edit里邊的內容(字串),轉化成整數
n_first:= strtointdef(first.text,0); //防止first Edit 內容為空時出錯,所以選用StrToIntDef函式
//同理 second Edit
n_second := strtointdef(second.text,0);
//然后,相加
n_third:= n_first+n_second;
//最后把n_third 的值變成 字串,放到third Edit 里顯示
third.Text := IntToStr( n_third );
end;
end.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/52133.html
標籤:語言基礎/算法/系統設計
