查看了很多书和网上的资料,里面有的也写了很多关于怎样定义一个类的方法,但却没写究竟要把类写在哪里?是unit的单元格中吗?还是哪里?如果是,我新建一个unit后会自动出现这些代码unit Unit3;
interface
implementation
end.
请帮我详细说明下类的属性、方法、名称、构造函数应该写在上面的什么位置。
敬谢!
我也不知道我写得对不对,照着网上人家说的方法试写了个TPerson类,发觉如果不定义function还好,一定义就老弹出[Error] Unit1.pas(19): Unsatisfied forward or external declaration: 'TPerson.GetAge'这样的错误提示,想了好外就没想出我哪错了,完整是这样:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TPerson = class
private
protected
public
name:string ;
function GetAge:Integer;
published
end;
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
类是不是写在这个地方。像VB那样单独放在一个model里吗