Home > Back-end >  Help! I'm new.
Help! I'm new.

Time:09-19

Type
TForm2=class (TForm)
First: TEdit;
Second: TEdit;
For: 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;
The begin
Third:=first + second;
end;

end.

CodePudding user response:

 third. Text:=inttostr (strtointdef (first. Text, 0) + strtointdef (second. Text, 0)); 

CodePudding user response:

That you define variables and Edit name are the same, not the feeling is very complicated?

CodePudding user response:

Looks like doesn 't help!

CodePudding user response:

First, second and third already change the property to an integer,. According to still have to use so many code?

CodePudding user response:

Procedure TForm2. Button1Click (Sender: TObject);
The begin
Third. Text:=inttostr (strtointdef (first. Text, 0) + strtointdef (second. Text, 0));
end;

CodePudding user response:

You 'd better use Delphi 6 to begin your study, Because in Delphi6 you can search for every functions provides the and procedures else, just press F1 for help. It is the fast way for study, just try it

CodePudding user response:

The
refer to the original poster weixin_39376810 response:
type
TForm2=class (TForm)
First: TEdit;
Second: TEdit;
For: 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;
The begin
Third:=first + second;
end;

End.


 procedure TForm2. Button1Click (Sender: TObject); 
Var
//it is best to let the name of variables and controls, convenient to yourself and others reading program, increase the readability of the program
N_first: integer;
N_second: integer;
N_third: integer;
The begin
//can do
//the first Edit the content inside the first (string), converted to an integer
N_first:=strtointdef (first. The text, 0); An error occurred when//prevent first Edit content is empty, so choose StrToIntDef function
//in the same way the second Edit
N_second:=strtointdef (second. The text, 0);
//then, add
N_third:=n_first + n_second;
//the last n_third value into a string, on the third Edit display
Third. Text:=IntToStr (n_third);
end;

End.
  • Related