delphi新手,一个简单的问题求解
做一个小程序:定义一个类,包含两个整形(x,y)和一个字符串(s)及方法output。output实现在窗体上的x,y位置,输出字符串s。
重载了 构造函数
程序代码:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type///// TMyClass = class private x:Integer; y:integer; s:string; public constructor Create(xx:Integer;yy:Integer;ss:string);overload; procedure out; end;/////// var Form1: TForm1; implementation {$R *.dfm} constructor TMyClass.Create(xx:Integer;yy:Integer;ss:string);///// begin x := xx; y := yy; s := ss; end; procedure TMyClass.out;///// begin Form1.Canvas.TextOut(x, y, s);///// end; procedure TForm1.Button1Click(Sender: TObject); var a:TMyClass;//// begin a := TMyClass.Create(100, 200, '百度知道');//// a.out;//// a.Free;//// end; end.