连接示例:使用 Lookup 对象

这个例子告诉如何检查一个对象是否被连接到一个数据源,然后建立一个查找对象来覆盖一个存在的色表。

例: 利用范围比较

在下面例子中,画面包含一个名为Rect1的矩形。

Private Sub BtnLookup_Click()

     Dim blnIsConnected As Boolean

     Dim lngIndex As Long

     Dim lngStatus As Long

     Dim strPropName As String

     Dim strSource As String

     Dim strFQSource As String

     Dim vtSourceObjects

     Dim LookupObject As Object

     Dim strFullname As String

     Dim blnIsEmpty As Boolean

 

     'Check to see if the rectangle's ForegroundColor

     'property is already connected to a data source

     Rect1.IsConnected "ForegroundColor", blnIsConnected, _

     lngIndex, lngStatus

 

     'If it is, use the Disconnect method to remove the

     'existing property connection

     If blnIsConnected Then

          Rect1.Disconnect "ForegroundColor"

     End If

 

     'If a ForegroundColor animation does not exist, build an

     'empty lookup animation object off of the rectangle

     If (TypeName(LookupObject) = "Nothing") Then

          Set LookupObject = Rect1.BuildObject("lookup")

     End If

 

     'Add levels to your lookup animation object with a range

     'comparison using the AddLevel method.The following

     'table will have inputs between 10 and 20 displaying the

     'color with the RGB value of 255 (red), 21 through 40

     'would display RGB 65535 and so on

     LookupObject.AddLevel 10, 255, 20

     LookupObject.AddLevel 20, 65535, 40

     LookupObject.AddLevel 40, 65280, 60

     LookupObject.AddLevel 60, 16711680, 80

     LookupObject.AddLevel 80, 8388736, 100

 

     'Use the SetSource method to connect the lookup animation

     'object to the data source object.This connection

     'overwrites any existing color table set up

     LookupObject.SetSource "AI1.F_CV", True

 

     'We have connected the InputValue property of the lookup

     'animation object to the data source.Now, we will

     'connect the animation object's OutputValue property to

     'the shape.Its output is connected to the object it is

     'animating.

     strFullname = LookupObject.FullyQualifiedName & _

     ".OutputValue"

     Rect1.Connect "ForegroundColor", strFullname, lngStatus

 

End Sub

同样的,可以能利用LookupExact方法和对象的ExactMatch属性创建一个精确值色表。下面例子告诉您如何做。

请再次注意,程序首先检查对象被连接到第一个地方,然后操作对象的属性。

例: 利用精确匹配查找

在下面例子中,画面包含一个名为Rect2的矩形。

Private Sub BtnLookupExact_Click()

     Dim blnIsConnected As Boolean

     Dim lngIndex As Long

     Dim lngStatus As Long

     Dim strPropName As String

     Dim strSource As String

     Dim strFQSource As String

     Dim vtSourceObjects

     Dim LookupObject As Object

     Dim strFullname As String

     Dim blnIsEmpty As Boolean

 

     'Check to see if the rectangle's ForegroundColor property

     'is already connected to a data source

     Rect2.IsConnected "ForegroundColor", blnIsConnected, _

     lngIndex, lngStatus

 

     'If it is, use the Disconnect method to remove the

     'property connection

     If blnIsConnected Then

          Rect2.Disconnect "ForegroundColor"

     End If

 

     'If a ForegroundColor animation does not exist, build an

     'empty lookup animation object off of the rectangle

     If (TypeName(LookupObject) = "Nothing") Then

          Set LookupObject = Rect2.BuildObject("lookup")

     End If

 

     'To create an exact match color table, the user can do

     'two things: (1) Call AddLevel with the same parameters

     'as a range comparison and set the ExactMatch property to

     'true OR (2) Call AddLevel without the second input

     'parameter.The following table will have inputs 10

     'displaying the color with an RGB value of 255

     '(red), 21 would display RGB 65535 and so on.

 

     LookupObject.AddLevel 10, 255, 20

     LookupObject.AddLevel 21, 65535, 40

     LookupObject.AddLevel 41, 65280, 60

     LookupObject.AddLevel 61, 16711680, 80

     LookupObject.AddLevel 81, 8388736, 100

     LookupObject.ExactMatch = True

 

     'Use the SetSource method to connect the lookup animation

     'object to the data source object.This connection

     'overwrites any existing ColorTable set up.

     LookupObject.SetSource "AI1.F_CV", True

     'We have connected the InputValue property of the lookup

     'animation object to the data source.Now, we will

     'connect the animation object's OutputValue property to

     'the shape.Its output is connected to the object it is

     'animating.

     strFullname = LookupObject.FullyQualifiedName & _

      ".OutputValue"

     Rect2.Connect "ForegroundColor", strFullname, lngStatus

 

End Sub

有关数据源的更多信息,请参阅创建画面手册。有关改变实时数据源的内容,请参考改变数据源一章。

相关信息

您最近了解过 iFIX 吗 ?

查看最新版 iFIX 的所有新功能。

让 iFIX 帮助您提高效率,降低成本。