以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]遍历WinForm.Control,找不到名称为""的控件! (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=47475) |
-- 作者:jnletao -- 发布时间:2014/3/11 9:18:00 -- [求助]遍历WinForm.Control,找不到名称为""的控件! --------------------------- 错误 --------------------------- 自定义代码执行出错,错误信息: System.NullReferenceException: 未设置对象变量或 With 块变量。 在 Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object Instance) 在 Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType) 在 Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSetComplex(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase) 在 UserCode.AFIELDCLOSE(Object[] Args) --------------------------- 确定 --------------------------- 自定义函数 Dim s As String For Each c As WinForm.Control In Forms(Args(0)).Controls For Each co As Col In Tables(Args(1)).Cols If co.AllowEdit = False Then If c.BindingField > "" AndAlso c.BindingField.Contains(Args(1) & "." & co.Name) Then Forms(Args(0)).Controls(c.Name).Enabled = False End If End If Next Next s = DataTables("授权表").GetComboListString("列名或按钮","用户名 = \'" & User.Name & "\' And 类型 = \'窗口\' And 不可编辑 = True And 表名或窗口 = \'" & Args(0) & "\'") s = “修改” If s IsNot Nothing Then For Each c As WinForm.Control In Forms(Args(0)).Controls If s.Contains(c.Name) Then Forms(Args(0)).Controls(c.Name).Enabled = False End If Next End If 错误应该在上段 是放在AfterLoad里执行的 [此贴子已经被作者于2014-3-11 9:19:35编辑过]
|
-- 作者:Bin -- 发布时间:2014/3/11 9:22:00 -- 如果你有分页面板,那么就会出现这个情况. 因为分页面板由两个无名次的PANEL组成 遍历之前应该变判断一下.如果C.NAME = "" 则不执行 If s.Contains(c.Name) andalso c.name <> "" Then Forms(Args(0)).Controls(c.Name).Enabled = False End If |
-- 作者:jnletao -- 发布时间:2014/3/11 9:32:00 -- OK,谢谢bin老师 c.name <> ""应该 写在前面 是吗 If c.name <> "" andalso s.Contains(c.Name) Then Forms(Args(0)).Controls(c.Name).Enabled = False End If |
-- 作者:Bin -- 发布时间:2014/3/11 9:36:00 -- 都可以 |