我定义一个类,给这个类传入参数,并让这个类的公共变量sr改变
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IniFiles, ComCtrls, Buttons;type
test = class
sr: string;
constructor create();overload;
constructor create(s: string); overload;
procedure zvoid;
end;implementationconstructor create(s: string);//错误??
begin
inherited create; sr := s; //sr错误 了
end;
procedure zvoid;
begin
ShowMessage(sr);
end;end.如果我在别一个类中调用的话,应是这样的procedure testMouse.FormCreate(Sender: TObject);
var
ts:test;
s:string;
begin
ts:=test.create(s);//错误 了?参数不正确
ts.zvoid;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IniFiles, ComCtrls, Buttons;type
test = class
sr: string;
constructor create();overload;
constructor create(s: string); overload;
procedure zvoid;
end;implementationconstructor create(s: string);//错误??
begin
inherited create; sr := s; //sr错误 了
end;
procedure zvoid;
begin
ShowMessage(sr);
end;end.如果我在别一个类中调用的话,应是这样的procedure testMouse.FormCreate(Sender: TObject);
var
ts:test;
s:string;
begin
ts:=test.create(s);//错误 了?参数不正确
ts.zvoid;
end;
解决方案 »
- 控件排列的问题
- vc代码转为delphi代码.
- 请问怎样动态的为FastReport报表中的文本框附值啊?
- 多语言转换是如何实现的?
- 在线等待,回答马上给分(关于存储过程参数问题!!!!!!!!!!)
- 如果TClientSocket没有连接到Tserversocket就继续连接,但过一段时间就会出错,怎么回事?
- 我开发的一个打印系统,请大家多多指点!
- 求助:Debugger Kernel BORDBK140.DLL or BORDBK140N.DLL is missing or could not be lo
- 有两个问题请作答!!在线等你
- 在WIN95中看不到ICON图标?
- Delphi的Flash控件怎么响应单击事件啊
- 关于读取数据速度问题
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TTest = class
private
str:string; procedure zvoid;
public
constructor Create(s:string);
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TTest }constructor TTest.Create(s: string);
begin
str := s;
end;procedure TForm1.Button1Click(Sender: TObject);
var
test : TTest;
begin
test := TTest.Create('abc');
test.zvoid;
end;procedure TTest.zvoid;
begin
ShowMessage(str);
end;end.