我要实现的功能是,在窗体显示的时候判断一下操作按钮是否可用
我将判断函数写在了一个公共函数文件GlobalUnit中,如下:因为在各个模块中操作按钮的类型可能不一致,有可能为ToolButton,SpeedButton等,所以按钮类型需要作为一个参数传递到函数中
----------------------------------------------------------------
Procedure PrivilegeControl(ClassNameStr: string; TempForm: TForm);
var
i,PrivilegeID :integer;
begin
for i:=0 to TempForm.ComponentCount-1 do
if (TempForm.Components[i].ClassName = ClassNameStr ) then
begin
PrivilegeID := TempForm.Components[i].Tag; //权限代码
//查找用户是否具有此使用权限
......
查询权限的SQL语句省略
......
if (Qry.RecordCount <> 0) then
TButton(TempForm.Components[i]).Enabled := True
else
TButton(TempForm.Components[i]).Enabled := False;
end;
end;
----------------------------------------------------------------
在某个模块窗体如下调用
procedure TForm1.FormShow(Sender: TObject);
begin
PrivilegeControl('ToolButton', Form1);
end;
procedure TForm2.FormShow(Sender: TObject);
begin
PrivilegeControl('SpeedButton', Form2);
end;
----------------------------------------------------------------
窗体创建方式均为模式窗体
try
Application.CreateForm(TNewForm, NewForm);
NewForm.ShowModal;
finally
NewForm.Free;
end;
----------------------------------------------------------------
运行时出现如下错误
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00421200 in module 'Project1.exe'. Read of address 00000010'. Process stopped. Use Step or Run to continue
应如何解决?
我将判断函数写在了一个公共函数文件GlobalUnit中,如下:因为在各个模块中操作按钮的类型可能不一致,有可能为ToolButton,SpeedButton等,所以按钮类型需要作为一个参数传递到函数中
----------------------------------------------------------------
Procedure PrivilegeControl(ClassNameStr: string; TempForm: TForm);
var
i,PrivilegeID :integer;
begin
for i:=0 to TempForm.ComponentCount-1 do
if (TempForm.Components[i].ClassName = ClassNameStr ) then
begin
PrivilegeID := TempForm.Components[i].Tag; //权限代码
//查找用户是否具有此使用权限
......
查询权限的SQL语句省略
......
if (Qry.RecordCount <> 0) then
TButton(TempForm.Components[i]).Enabled := True
else
TButton(TempForm.Components[i]).Enabled := False;
end;
end;
----------------------------------------------------------------
在某个模块窗体如下调用
procedure TForm1.FormShow(Sender: TObject);
begin
PrivilegeControl('ToolButton', Form1);
end;
procedure TForm2.FormShow(Sender: TObject);
begin
PrivilegeControl('SpeedButton', Form2);
end;
----------------------------------------------------------------
窗体创建方式均为模式窗体
try
Application.CreateForm(TNewForm, NewForm);
NewForm.ShowModal;
finally
NewForm.Free;
end;
----------------------------------------------------------------
运行时出现如下错误
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00421200 in module 'Project1.exe'. Read of address 00000010'. Process stopped. Use Step or Run to continue
应如何解决?
解决方案 »
- 动态分配控件的方法!!!!!!!!!!!!!
- delphi中ado如何动态连接数据库
- 如何设置excel单元格格式为文本型?(在线等)
- dbgrid问题.
- 怎样把DBGrid当前显示的记录打印出来!?
- 關於Win2K無法關機
- 数学还未忘的进来瞧瞧,已知一个等腰三角形的三角顶点的坐标,如何求出它的外接圆的圆心坐标和半径。
- delphi 中两个不同的数据表比较运算问题
- 如果实现程序中的中英文版本的问题
- 关于API函数AnimateWindow()......
- 急!在线等待............由于安装了第三方控件(FormulaOne,即F1Book6.1)!程序不打包,想直接使用!在新系统环境中则不能运行!报"没有注册类
- 为什么给Form增加的属性在Object Inspector中看不到?
function GetContolStatus(Sender: TObject;
)
begin
if TControl(Sender).Enabled then
..........;
else
......... ;
end;
我跟踪了一下,应该是窗体没有创建,但是我的事件调用是在窗体显示事件里啊,在这之前窗体应该已经创建了才对啊