我在delphi中有SelectTable:integer是private
还有函数SetSelect和GetSelect是public
请问该怎么做啊?
另外,下面是我写的SetSelect和GetSelect程序,请大家看看对不对啊,谢谢。
我觉得有问题,但不知道问题出在哪里。
Procedure SetSelect()
Begin
SelectTable:=1;
End;Function GetSelect():Integer;
Begin
Result:=SelectTable;
End;
解决方案 »
- 请教高手关于多媒体问题!
- 如何得到应用程序列表?
- 一个关于SQL报错的问题,请高手指点迷津!比较急,在线等!
- 如何屏蔽输入框中的 鼠标右键?
- 请问大家怎么样用程序监控文件的拷贝的情况,即当有文件拷贝时就复制一份到指定的地方?
- 哪里有类似QQ这样子的卡片式组件?谢谢!!
- 有一delphi类型库开发构件的问题,请大家帮忙!
- 千山一刀之忍者神龟进来拿分!!!
- 哪有webbrowser做的小浏览器?
- 请局域网高手帮我!
- 请问我在treeview中为iiem中的每一项申请的内存数据在最后需要手动释放吗?
- 把TADOQuery的数据传给TClientDataSet一定要TDataSetProvide吗,还有其他方式吗?
private
FSelectTable: Integer;
function GetSelect: Integer;
procedure SetSelect(Value: Integer);
public // 建议用 published
property SelectTable: Integer read GetSelect write SetSelect;
end;procedure TMyClass.SetSelect(Value: Integer)
begin
FSelectTable := Value;
end;function TMyClass.GetSelect:Integer;
begin
Result := FSelectTable;
end;
property SelectTable: Integer read GetSelect write SetSelect;
然后按 Ctrl + Shift + C,SetSelect、GetSelect 函数的声明、定义就自动给出了:
procedure TMyClass.SetSelect(Value: Integer)
beginend;function TMyClass.GetSelect:Integer;
beginend;
方便吧?btw, 楼主是从 Basic 转过来的?
报错:expected ‘:’ but ‘=’ found
我把程序罗列如下,你看看是不是程序修改的位置不对啊?
unit Employee_Find;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBCtrls, StdCtrls, ExtCtrls, Grids, DBGrids, Mask;type
TF_Employee_find = class(TForm)
TMyclass = class
…… private
FSelectTable:Integer;
public
property SelectTable: Integer read GetSelect write SetSelect;
function GetSelect: Integer;
procedure SetSelect(Value: Integer);
end;var
F_Employee_find: TF_Employee_find;
implementationuses U_DataModuleMain,employee;{$R *.dfm}procedure TMyClass.SetSelect(Value:Integer);
begin
FSelectTable:=Value;
end;function TMyClass.GetSelect:integer;
begin
Result:=FSelectTable;
end;
谢谢你的提醒。我把程序修改如下:
type
TMyclass = class
private
FSelectTable:Integer;
public
property SelectTable: Integer read GetSelect write SetSelect; //第51行
function GetSelect: Integer;
procedure SetSelect(Value: Integer);
end;
但是为何property SelectTable: Integer read GetSelect write SetSelect;此句通不过。
报错信息:[Error] Employee_Find.pas(51): Field or method identifier expected
我也不知道这句是什么意思,能简单的解释一下吗?
我看过help了,相关property的内容很多,看得云里雾里的。
谢谢。
TMyclass = class
private
FSelectTable:Integer;
protected
function GetSelect: Integer;
procedure SetSelect(Value: Integer);
published
property SelectTable: Integer read GetSelect write SetSelect; //第51行
end;
implementation
function TMyclass.GetSelect: Integer;
begin
result:=FSelectTable;
end;
procedure TMyclass.SetSelect(Value: Integer);
begin
FSelectTable:=value;
end;
如何在procedure TF_Employee_find.btn_cancelClick(Sender: TObject);中
使用TMyClass.SetSelect(2)?2、若把GetSelect和SetSelect定义成Protected,那岂不是别的pas文件就无法调用它们两个了?
我需要别的pas也可以调用它们,程序应如何改动?请指教,谢谢。
既然是用了 property 机制,就没必要调 SetXXX 了,直接写:
var
MyObj: TMyClass;
begin
MyObj := TMyClass.Create;
MyObj.SelectTable := 1234; // <<<<<
MyObj.Free;
end; 2. 虽然GetSelect和SetSelect是Protected,但是 SelectTable 确是 published 的,可以在别的单元里读写。