A
awfigsk
Unregistered / Unconfirmed
GUEST, unregistred user!
[red]TAddrBook = class
private
//一些私有成员
public
constructor Create;
destructor Destroy;override
GetCurIndex: Integer;
FindRecord(strString): Integer;
GetRecord(nIndex:Integer): String;
SetRecord(nIndex:integer
strRec:String): Boolean;
AddRecord(strRec:String): Boolean
DelRecord(nIndex):Boolean
//其它共有成员函数
end;[/red]
//==========================================
var Form1: TForm1;
AddrBook: TAddrBook;
nCurRec: Integer;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
AddrBook := TAddrBook.Create;
nCurRec := AddrBook.GetCurIndex;
end;
procedure TForm1.FormClose(Sender: TObject
var Action: TCloseAction);
begin
AddrBook.Free;
end;
//添加按钮
procedure TForm1.Button1Click(Sender: TObject);
begin
if not AddrBook.AddRecord(memo1.Text) then
ShowMessage("error");
end;
//删除按钮
procedure TForm1.Button2Click(Sender: TObject);
begin
if not AddrBook.DelRecord(nCurRec) then
ShowMessage("error");
end;
//修改按钮
procedure TForm1.Button3Click(Sender: TObject);
begin
if not AddrBook.SetRecord(nCurRec, memo1.Text) then
ShowMessage("error");
end;
//查找按钮
procedure TForm1.Button4Click(Sender: TObject)
begin
memo1.Text := AddrBook.GetRecord(FindRecord(memo1.Text));
end;
我想请问,如果红色这部分代码和后面的内容在同一个单元内,如果其public这部分函数说
明在private中,那么是不是后面的button中click事件可以用AddrBook.方式来使用其中的
变量和函数?
如果这两部分内容在两个单元内,放在private中,还可以这样吗?
private
//一些私有成员
public
constructor Create;
destructor Destroy;override
GetCurIndex: Integer;
FindRecord(strString): Integer;
GetRecord(nIndex:Integer): String;
SetRecord(nIndex:integer
strRec:String): Boolean;
AddRecord(strRec:String): Boolean
DelRecord(nIndex):Boolean
//其它共有成员函数
end;[/red]
//==========================================
var Form1: TForm1;
AddrBook: TAddrBook;
nCurRec: Integer;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
AddrBook := TAddrBook.Create;
nCurRec := AddrBook.GetCurIndex;
end;
procedure TForm1.FormClose(Sender: TObject
var Action: TCloseAction);
begin
AddrBook.Free;
end;
//添加按钮
procedure TForm1.Button1Click(Sender: TObject);
begin
if not AddrBook.AddRecord(memo1.Text) then
ShowMessage("error");
end;
//删除按钮
procedure TForm1.Button2Click(Sender: TObject);
begin
if not AddrBook.DelRecord(nCurRec) then
ShowMessage("error");
end;
//修改按钮
procedure TForm1.Button3Click(Sender: TObject);
begin
if not AddrBook.SetRecord(nCurRec, memo1.Text) then
ShowMessage("error");
end;
//查找按钮
procedure TForm1.Button4Click(Sender: TObject)
begin
memo1.Text := AddrBook.GetRecord(FindRecord(memo1.Text));
end;
我想请问,如果红色这部分代码和后面的内容在同一个单元内,如果其public这部分函数说
明在private中,那么是不是后面的button中click事件可以用AddrBook.方式来使用其中的
变量和函数?
如果这两部分内容在两个单元内,放在private中,还可以这样吗?