从表单中调用类的私有方法 [英] Calling a class' private method from a form

查看:75
本文介绍了从表单中调用类的私有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用类在对话框模式下打开的

表格来回传递变量。

我创建了一个在show方法中调用表单的类,比如

所以:


Public Sub Show()

''此方法显示用于获取信息的表单

如果sWhereInt =""然后

DoCmd.OpenForm sFormNameInt,acNormal ,,, acFormAdd,_

acDialog

Else

DoCmd.OpenForm sFormNameInt,acNormal,sWhereInt,_

acFormEdit,acDialog

结束如果

结束子


我使用以下方法收集参数值:


属性设置SetParam(sName为字符串,vValue为变体)


dParamDict(sName)= vValue


结束属性


其中dParamDict是一个Scripting.Dictionary对象,已在

类初始化时设置。


我想定义一个私有方法(或者必要时可以使用属性)

表单可以检索参数值。我所有的努力都很难实现。


任何人都可以提供任何指导吗?


非常感谢,


Eric

Hi,
I''m trying to use a class to pass variables back and forth from a
form opened in dialog mode.
I have created a class which invokes a form in its show method, like
so:

Public Sub Show()
'' This method shows the form used to get the info
If sWhereInt = "" Then
DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _
acDialog
Else
DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _
acFormEdit, acDialog
End If
End Sub

I collect parameter values using:

Property Let SetParam(sName As String, vValue As Variant)

dParamDict(sName) = vValue

End Property

where dParamDict is a Scripting.Dictionary object which has been set on
class initialization.

I would like to define a private method (or property if necessary)
visible to the form to retrieve parameter values. All of my efforts so
far have failed.

Can anyone provide any guidance?

Many thanks,

Eric

推荐答案

呃*********** @ gmail.com 写道:

我''我试图使用一个类来从在对话框模式下打开的
表单来回传递变量。
我创建了一个类,它在show方法中调用一个表单,比如
所以:

Public Sub Show()
''此方法显示用于获取信息的表单
如果sWhereInt =""然后
DoCmd.OpenForm sFormNameInt,acNormal ,,, acFormAdd,_
acDialog
其他
DoCmd.OpenForm sFormNameInt,acNormal,sWhereInt,_
acFormEdit,acDialog <结束如果
结束Sub

我使用以下方法收集参数值:

Property Let SetParam(sName As String,vValue As Variant)

dParamDict(sName)= vValue

结束属性

其中dParamDict是一个Scripting.Dictionary对象,已在类初始化时设置。

我想定义一个私有方法(或者必要时可以使用属性)
对表单可见以检索参数值。我所有的努力都很失败。

任何人都可以提供任何指导吗?
Hi,
I''m trying to use a class to pass variables back and forth from a
form opened in dialog mode.
I have created a class which invokes a form in its show method, like
so:

Public Sub Show()
'' This method shows the form used to get the info
If sWhereInt = "" Then
DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _
acDialog
Else
DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _
acFormEdit, acDialog
End If
End Sub

I collect parameter values using:

Property Let SetParam(sName As String, vValue As Variant)

dParamDict(sName) = vValue

End Property

where dParamDict is a Scripting.Dictionary object which has been set on
class initialization.

I would like to define a private method (or property if necessary)
visible to the form to retrieve parameter values. All of my efforts so
far have failed.

Can anyone provide any guidance?




首先,只是因为表格是通过类中的代码打开的,不是
意味着表单可以访问类的私有方法。你有

来提供一个公共界面来检索东西。来自dParamDict

对象只需添加东西即可它。没有进一步的细节
你尝试过的
我会说最简单的检索

参数的方法是提供一个以密钥作为参数的公共方法

并返回与dParamDict对象中的键相关联的值。


如果你想要的是使dParamDict对象仅用于

打开的表单然后在

表单'模块中创建一个类似的dParamDict对象,并在打开之后将其设置为等于类

的dParamDict对象表格。




First off, just because the form is opened by code in the class does not
mean that the form has access to private methods of the class. You have
to provide a public interface to retrieve "things" from the dParamDict
object just has you had to to add "things" to it. Without further detail
of what you have tried I would say the simplest way to retrieve
parameters is to provide a public method that takes a key as an argument
and returns the value associated with the key from the dParamDict object.

If what you are after is to make the dParamDict object available only to
the form that is opened then create a similar dParamDict object in the
form''s module and set it equal to the dParamDict object of the class
after you open the form.



< er *********** @ gmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
<er***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

我正在尝试使用类在对话框模式下打开的
表单来回传递变量。


您打算如何使用对话框表格?使用对话框表单意味着所有代码

STOPS并等待表单完成。事实上,你甚至不能在这里使用内置的

菜单。我认为你在对话框表格的概念,

和模型表格之间感到困惑。


你可以在这里阅读它们:

http://www.members.shaw.ca /AlbertKal...log/Index.html


我创建了一个在其show方法中调用表单的类,如
所以:


好​​的,您可以理解模型表单和

对话框表单之间的区别,但请牢记以上内容:


DoCmd.OpenForm sFormNameInt,acNormal,sWhereInt,_
acFormEdit,acDialog
Hi,
I''m trying to use a class to pass variables back and forth from a
form opened in dialog mode.
How are you going to use a dialog form? Using a dialog form means all code
STOPS and waits for the form to finish. In fact, you can''t even use built in
menus here. I think you are confused between the concepts of a dialog form,
and a model form.

You can read about them here:

http://www.members.shaw.ca/AlbertKal...log/Index.html

I have created a class which invokes a form in its show method, like
so:
Ok, it is possible you understand the difference between model forms, and
dialog forms, but keeping the above in mind:


DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _
acFormEdit, acDialog




请记住,这一点代码将等待unter上面的表单是

关闭,或踢出对话框模式。如果表格已经关闭,那么你就不能从表格中获取价值......你能吗?


你*可以*暴露自己的价格只要您将其声明为

public,就可以使用上述表格。并且,假设您刚刚阅读了我的上述文章,那么您可以去:


msgbox" My Custom Properity is &安培;表格(sFormNameInt)。MyCustomProp

-

Albert D. Kallal(访问MVP)

加拿大艾伯塔省埃德蒙顿 pl ***************** @ msn.com
http://www.members。 shaw.ca/AlbertKallal



Keep in mind, a this point the code will wait unter the above form is
closed, or kicked out of dialog mode. If the form is closed, then you can''t
grab the values from the form...can you?

You *can* expose propeites in the above form as long as you declare them as
public. And, assuming you just read my above article, then you can go:

msgbox "My Custom Properity is " & forms("sFormNameInt").MyCustomProp
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal


Albert D. Kallal写道:
Albert D. Kallal wrote:
< er ********* **@gmail.com>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
<er***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

我正在尝试使用类在对话框模式下打开的
表单来回传递变量。
Hi,
I''m trying to use a class to pass variables back and forth from a
form opened in dialog mode.



如何你打算用对话框吗?使用对话框表单意味着所有代码STOPS并等待表单完成。事实上,你甚至不能在这里使用内置的菜单。我认为你在对话形式的概念和模型形式之间感到困惑。

你可以在这里阅读它们:

http://www.members.shaw.ca/AlbertKal...log/Index .html

我创建了一个在其show方法中调用表单的类,如
所以:
I have created a class which invokes a form in its show method, like
so:



好吧,你可以理解模型表单和
对话框表单之间的区别,但要记住以上几点:


Ok, it is possible you understand the difference between model forms, and
dialog forms, but keeping the above in mind:

DoCmd.OpenForm sFormNameInt,acNormal ,, sWhereInt ,_
acFormEdit,acDialog
DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _
acFormEdit, acDialog



请记住,这一点代码将等待上面的表单关闭,或者踢出对话框模式。如果表格已经关闭,那么你就无法从表格中获取价值......你能吗?

你*可以*以上述形式公开propeites只要你宣称他们是公开的。并且,假设您刚刚阅读了我的上述文章,那么您可以去:

msgbox" My Custom Properity is" &安培;表格(sFormNameInt)。MyCustomProp


Keep in mind, a this point the code will wait unter the above form is
closed, or kicked out of dialog mode. If the form is closed, then you can''t
grab the values from the form...can you?

You *can* expose propeites in the above form as long as you declare them as
public. And, assuming you just read my above article, then you can go:

msgbox "My Custom Properity is " & forms("sFormNameInt").MyCustomProp




您可以通过对话模式踢出表格(以对话模式打开)

将表单的可见性设置为False(通常使用命令按钮

在对话框模式下打开的表单中)。这样就可以打开表单并且可以访问它的

变量,并允许代码继续通过调用代码中的.OpenForm

调用,这样你就可以获取值,然后执行

表格上的DoCmd.Close。


-

''------------ ---

''John Mishefske

''---------------



You can kick the form (opened in Dialog mode) out of Dialog mode by
setting the form''s visibility to False (typically using a command button
in the form opened in Dialog mode). This leaves the form open and its
variables accessible and allows code to continue past the .OpenForm
call in the calling code so that you can grab values and then do a
DoCmd.Close on the form.

--
''---------------
''John Mishefske
''---------------


这篇关于从表单中调用类的私有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆