我要实现的功能是,在窗体显示的时候判断一下操作按钮是否可用
我将判断函数写在了一个公共函数文件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
应如何解决?