我在书店中找不到相关的书籍,请各位简要说一下Delphi中Private和Public 的使用。在下将不胜感激。先在这里谢国了。
解决方案 »
- 动态显示出是计划内还是计划外的问题
- 如何实现将全屏游戏切换为窗口型?请多指教!
- 能推荐一本学习delphi网络编程的好书么?谢谢了哦,
- 如何让应该程序运行时不在任务栏上显示?
- 双休啊,终于可以好好休息一下了!想散点分!
- 高分求教:请问怎样把DBGRID中某字段的值显示为‘*’!(急!!!!)
- 怎样将dxdbgrid控件中的"Drag a column header here to group by that column"
- 我爆笑
- 在C/S结构中,如何不让两个客户操作同一动作?
- SCPI指令TCP通信,viOpen错误
- 如何才能打开加密的paradox数据库,我忘记口令了,请高手给指点了。
- 想建个论坛,看看各位有没有想当版主的!!
private
i:integer;
public
procedure foo();
end;class myClass
{
private:
int i;
public:
void foo();
}
unit Unit1;
//Form上放置一Edit和Button,双击Button1写事件。Form的private部分添加一成员Foo
//在implementation部分添加一函数(不属于Form1的成员)IncFoo,其中可访问Form1的
//private成员Foo (而在其它unit中不能直接访问Foo)interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Foo: integer;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function IncFoo(Sender: TForm1; n: integer = 1): integer;
begin
Inc(Sender.Foo, n);
Result := Sender.Foo;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := IntToStr(IncFoo(Self, 1));
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Foo := 0;
end;end.
#include "stdafx.h"
#include<iostream.h>
class myClass
{
private:
void FooPrv();
public:
void FooPub();
};
void myClass::FooPub()
{
cout<<"myClass::FooPub() called"<<endl;
};
void myClass::FooPrv()
{
cout<<"myClass::FooPriv()"<<endl;
};
int main(int argc, char* argv[])
{
myClass tmp;
tmp.FooPrv ();//如果是这样,根本就无法通过编译,除非改为tmp.FooPub();
return 0;
}Delphi中:(一个Console工程,在工程文件的begin..end之间调用main方法.)
unit Unit1;interface
type
myClass=Class
private
procedure FooPrv();
public
procedure FooPub();
end;
procedure main();
var
tmp:myClass;
implementation
procedure myClass.FooPrv();
begin
Writeln('myClass.FooPrv() called.');
end;
procedure myClass.FooPub();
begin
Writeln('myClass.FooPub() called.');
end; procedure main();
var s:string;
begin
tmp:=myClass.Create ;
tmp.FooPrv ;//不仅可以通过编译,而且还可以正常输出'myClass.FooPrv() called.'
tmp.Free ;
end;end.
应该淘汰掉。