为什么StrToInt没能得到小弟我输的数字,求大神
为什么StrToInt没能得到我输的数字,求大神
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
RArray = array[0..1] of Integer; //定义一个数组
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure GetR(R: RArray);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetR(R: RArray);
begin
R[0] := StrToInt(Edit1.Text);
R[1] := StrToInt(Edit2.Text);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
R: RArray;
begin
GetR(R);
Label1.Caption := IntToStr(R[0]); //这边输出的结果跟我输的就不一样
Label2.Caption := IntToStr(R[1]);
end;
end.
------解决方案--------------------
procedure TForm1.GetR(R: RArray);
改成
procedure TForm1.GetR(var R: RArray);
即可
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
RArray = array[0..1] of Integer; //定义一个数组
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure GetR(R: RArray);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetR(R: RArray);
begin
R[0] := StrToInt(Edit1.Text);
R[1] := StrToInt(Edit2.Text);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
R: RArray;
begin
GetR(R);
Label1.Caption := IntToStr(R[0]); //这边输出的结果跟我输的就不一样
Label2.Caption := IntToStr(R[1]);
end;
end.
------解决方案--------------------
procedure TForm1.GetR(R: RArray);
改成
procedure TForm1.GetR(var R: RArray);
即可