delphi 在类中定义的函数不能给类中的字段赋值么?? 代码如下 (点击按钮2 就会报错 Access violation )
unitUnit1;interfaceusesWinapi.Windows,Winapi.Messages,System.SysUtils,System.Variants...
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.Math;
type
Tmyclass=class
private
public
m,n:Integer;
function myfuc2(const x:Integer;const y:Integer):Integer;
end;
TForm1 = class(TForm)
Button2: TButton;
Edit2: TEdit;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
amy2:Tmyclass;
implementation
{$R *.dfm}
function Tmyclass.myfuc2(const x:Integer;const y :Integer):Integer;
begin
m:=x; // 不能赋值?
n:=y;
Result:=m+n;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
x,y:Integer;
begin
x:=2;
y:=3;
Edit2.Text:=IntToStr(amy2.myfuc2(x,y))
end;
end. 展开
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.Math;
type
Tmyclass=class
private
public
m,n:Integer;
function myfuc2(const x:Integer;const y:Integer):Integer;
end;
TForm1 = class(TForm)
Button2: TButton;
Edit2: TEdit;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
amy2:Tmyclass;
implementation
{$R *.dfm}
function Tmyclass.myfuc2(const x:Integer;const y :Integer):Integer;
begin
m:=x; // 不能赋值?
n:=y;
Result:=m+n;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
x,y:Integer;
begin
x:=2;
y:=3;
Edit2.Text:=IntToStr(amy2.myfuc2(x,y))
end;
end. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询