Data Access Worldwide Knowledge Base

Article ID 2203
Article Title HOWTO: Find Out if a different Parent record was selected
Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2203
KBase Category VDF (GENERAL)
Date Created 01/03/2006
Last Edit Date 01/03/2006


Article Text
QUESTION:
How can I find out if a different parent record was selected?

ANSWER:
Data Dictionaries do not maintain a special property but there are two ways you can do it:

1) Should_Save in combination with Changed_State tells you whether the structure detected a change while none of the individual fields was changed. You could test by adding code like:

Function IsOneOfTheParentsChanged Handle hoDDO Returns Boolean
    Integer iServers iServer
    Handle hoServerDDO
    Boolean bChanged

    Get Data_Set_Server_Count Of hoDDO To iServers
    Decrement iServers
    For iServer From 0 To iServers
        Get Data_Set_Server Of hoDDO iServer To hoServerDDO
        If (hoServerDDO > 0) Begin
            Get Changed_State Of hoServerDDO To bChanged
            If (bChanged) Begin
                Function_Return True
            End
            Else Begin
                Get IsOneOfTheParentsChanged hoServerDDO To bChanged
                If (bChanged) Begin
                    Function_Return True
                End
            End
        End
    Loop

    Function_Return False
End_Function // IsOneOfTheParentsChanged


Function IsNewParentSelected Returns Boolean
    Boolean bChanged bShouldSave

    Get Should_Save To bShouldSave
    Get Changed_State To bChanged
    If (bShouldSave And (Not (bChanged))) Begin
        Get IsOneOfTheParentsChanged Self To bChanged
    End

    Move (bShouldSave And (Not (bChanged))) To bChanged

    Function_Return bChanged
End_Function // IsNewParentSelected

to your DataDictionary subclass. Call the function IsNewParentSelected of the DataDictionary object you want to be informed about. The function returns true when ONLY another parent was selected. If a NEW parent was selected AND one or more fields were changed, the function returns FALSE even though a new parent was selected.

2) You can collect row id's (record id in versions prior to VDF11) in an array. The following code will only work for VDF11 since structs and arrays are used.

Struct tDDORowId
    Handle hoDDO
    RowId riRecord
End_Struct

Property tDDORowId[] pParentDDOInfo

Procedure Request_Find Integer eFindMode Integer iFile Integer iIndex
    tDDORowId[] ParentDDOInfo
    
    Forward Send Request_Find eFindMode iFile iIndex
    
    Send DoRetrieveParentDDORowIds Self (&ParentDDOInfo)

    Set pParentDDOInfo To ParentDDOInfo
End_Procedure // Request_Find


Procedure Clear_Main_File
    tDDORowId[] ParentDDOInfo
    
    Forward Send Clear_Main_File

    Set pParentDDOInfo To ParentDDOInfo
End_Procedure // Clear_Main_File


Procedure DoRetrieveParentDDORowIds Handle hoDDO tDDORowId[] BYREF ParentDDOInfo
    Integer iServers iServer iElements
    Handle hoServerDDO

    Get Data_Set_Server_Count Of hoDDO To iServers
    Decrement iServers
    For iServer From 0 To iServers
        Get Data_Set_Server Of hoDDO iServer To hoServerDDO
        If (hoServerDDO > 0) Begin
            Move (SizeOfArray (ParentDDOInfo)) To iElements
            Move hoServerDDO To ParentDDOInfo[iElements].hoDDO
            Get CurrentRowId Of hoServerDDO To ParentDDOInfo[iElements].riRecord
            Send DoRetrieveParentDDORowIds hoServerDDO (&ParentDDOInfo)
        End
    Loop
End_Procedure // DoRetrieveParentDDORowIds


Function IsNewParentSelected Returns Boolean
    tDDORowId[] ParentDDOInfo
    Integer iElements iElement
    RowId riRecord
    
    Get pParentDDOInfo To ParentDDOInfo

    Move (SizeOfArray (ParentDDOInfo)) To iElements
    Decrement iElements
    For iElement From 0 To iElements
        Get CurrentRowId Of ParentDDOInfo[iElement].hoDDO To riRecord
        If (Not (IsSameRowId (riRecord, ParentDDOInfo[iElement].riRecord))) Begin
            Function_Return True
        End
    Loop

    Function_Return False
End_Function // IsNewParentSelected


Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.