Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Make a copy of the current record in a datadictionary object.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Make a copy of the current record in a datadictionary object.

    Ever tried to find an easy way to make a copy of the current record in a datadictionary object? The old technique by putting a zero in recnum or setting DF_FILE_STATUS to DF_FILE_INACTIVE only works for the record buffer and does not fire the needed messages like Creating in the DDO. So I (finally) got tired to work around it and made this little procedure that takes the current record and prepare a new record with a copy of the data. It takes care of parent DDOs even if they are constained. This can be placed in a subclass of a datadictionary if you want to.

    Code:
        Procedure DoMakeNewCopy
            Integer iMaxField iCurField iDDFile iCurFile iMaxFile iParentFile
            Handle hParentDD
            RowID rwOld rwCurrentID
            RowID[] rwParents
            Boolean bFound
            String sData
            Get Data_Set_Server_Count to iMaxFile
            Decrement iMaxFile
            For iCurFile from 0 to iMaxFile
                Get Data_Set_Server iCurFile to hParentDD
                Get CurrentRowId of hParentDD to rwParents[iCurFile]
            Loop
            Get Main_File to iDDFile
            Get_Attribute DF_FILE_NUMBER_FIELDS of iDDFile to iMaxField
            Get CurrentRowId to rwOld
            Send Clear
            Move (FindByRowID(iDDFile, rwOld)) to bFound
            If bFound Begin
                For iCurFile from 0 to iMaxFile
                    Get Data_Set_Server iCurFile to hParentDD
                    Get CurrentRowId of hParentDD to rwCurrentID
                    If (not(IsSameRowID(rwCurrentID, rwParents[iCurFile]))) Begin
                        Get Main_File of hParentDD to iParentFile
                        Send FindByRowId of hParentDD iParentFile rwParents[iCurFile]
                    End
                Loop
                For iCurField from 1 to iMaxField
                    Get_Field_Value iDDFile iCurField to sData
                    Set Field_Changed_Value iCurField to sData
                Loop
                Clear iDDFile
            End
        End_Procedure
    Call this procedure when you need a copy of the current record in the DDO. After you have called the procedure just change whatever field or parent DDO record needed to save the new record if any. This may be needed if any of your index requires it.

    Remember to send Request_save when done.

  2. #2
    Join Date
    Feb 2009
    Location
    Hengelo, Netherlands
    Posts
    10,869

    Default Re: Make a copy of the current record in a datadictionary object.

    Alan,

    Nice work. One question; did you test this with multiple levels of parent tables? And constraints being active?
    Regards,
    Data Access Worldwide
    Vincent Oorsprong

  3. #3

    Default Re: Make a copy of the current record in a datadictionary object.

    Hi Vincent, and thanks

    I have an application where I am about to use this multiple places, but I have tested this in one place in the application. The current DDO has several DDO servers that in return has more DDO servers. And the current DDO is constrained to one of the DDO servers. And this works as expected.

    Code extract from a working example:
    Code:
        Object N43_DD is a N43_DataDictionary
        End_Object    // N43_DD
    
        Object N42_DD is a N42_DataDictionary
            Send Remove_Server_file N120.file_number
        End_Object    // N42_DD
    
        Object Land_DD is a Land_DataDictionary
        End_Object    // Land_DD
    
        Object N12_DD is a N12_DataDictionary
    
            Set DDO_Server to N43_DD
            Set DDO_Server to N42_DD
            Set DDO_Server to Land_DD
    
        End_Object    // N12_DD
    
    
        Object N100_DD is a N100_DataDictionary
        End_Object    // N100_DD
    
        Object N25_DD is a N25_DataDictionary
    
            Set DDO_Server to N12_DD
            Set DDO_Server to N100_DD
            Set Constrain_File to N12.File_Number
    
            Procedure OnConstrain
                Forward Send OnConstrain
                Constrain n25 as (diaconstr(current_object))
            End_Procedure
    
    
            Procedure DoCopy
                
                Begin_Transaction
                    
                    (some code that changes the current record and saves it, all with field_changed_value and request_save)
    
        
                    Send DoMakeNewCopy
    
                    Set Field_Changed_Value Field (a date field) to (a new date)
        
                    Send request_save
                End_Transaction
                
            End_Procedure
    
        End_Object    // N25_DD
    The diaconstr function is defined in the view.
    This is a very trimmed out code but it is just to illustrate the DDO structure used for testing the procedure. As you can se it also makes use of at transaction to make sure that the change of the old record is only carried out if the new copy of the record is saved correctly.

    I think it will work with other types of constraints as well since the constrains does not changes while the copy is being prepared. It is getting the current rowID of the parent DDOs of the current DDO and refinding them after a clear. And I believe the FindByRowID message for a DD is respecting the current constraint sets and also finding all ancestor DD exactly like the Find message. So it should be quite safe to use.

    The test to see if the RowID in a server DDO is the same as the feched RowID before the clear is to prevent that the Parent DDO is "refinding" the same record and making a full DEO update since that is not needed at this point. This would be the case of at contrainted-to parent DDO.

    One thing to look out for might be to make sure that DDO field buffers for extended fields like text and binary are defined with either the DefineExtendedField or DefineAllExtendedFields messages.
    Last edited by Allan Greis Eriksen; 27-Jan-2010 at 05:44 AM.

  4. #4
    Join Date
    Feb 2009
    Location
    Maasland, The Netherlands
    Posts
    2,605

    Default Re: Make a copy of the current record in a datadictionary object.

    Allan,

    It looks good. Until now I used Duplicate_Record. I picked it up somewhere from this forum. Your code seems to be more efficient.

    AFAIK my current procedure doesn't support text fields. Until now I didn't really need it.
    Does DoMakeNewCopy support text fields?
    Best regards,

    Peter van Mil
    Appvantage b.v.

  5. #5

    Default Re: Make a copy of the current record in a datadictionary object.

    Absolutely. You just have to define the DDO field buffer in the DDO since it is not done with text and binary fields. Use the DefineExtendedField iFieldnumber or Send DefineAllExtendedFields messages. Check the online help for these messages

  6. #6
    Join Date
    Feb 2009
    Location
    Somewhere in Vermont, USA - unless I'm not
    Posts
    11,085

    Default Re: Make a copy of the current record in a datadictionary object.

    Quote Originally Posted by Allan Kim Eriksen View Post
    Absolutely. You just have to define the DDO field buffer in the DDO since it is not done with text and binary fields. Use the DefineExtendedField iFieldnumber or Send DefineAllExtendedFields messages. Check the online help for these messages
    I just tested this with a file that has a 5K note field & 2 parents & 1 grandparent - only change I made was to Send DefineAllExtendedFields in the DD & added a Send Request_Save line at the bottom of this procedure.

    Copied everything perfectly.

    Thanks Allan!
    Garret

    Time for an oldie but goodie:

    "If it ain't broke, you're not trying." - Red Green

  7. #7
    Join Date
    Feb 2009
    Location
    Boxtel, The Netherlands
    Posts
    1,038

    Default Re: Make a copy of the current record in a datadictionary object.

    Peter,

    I'm also using "duplicate_reord" and it basically does the same as Allan's code. I haven't had any problems using "duplicate_record" so far.
    Kind regards,

    Hans van de Laar
    Data Access Europe

  8. #8
    Join Date
    Feb 2009
    Location
    Maasland, The Netherlands
    Posts
    2,605

    Default Re: Make a copy of the current record in a datadictionary object.

    Once I have read about those messages. With my current solution it doesn't work. I will give DoMakeNewCopy a try (not now, but before the EDUC).

    Thanks.
    Best regards,

    Peter van Mil
    Appvantage b.v.

  9. #9
    Join Date
    Feb 2009
    Location
    Perth, Western Australia
    Posts
    1,477

    Default Re: Make a copy of the current record in a datadictionary object.

    Hi Allan,

    We have something very similar, Copy_Buffer, which instead of recording the current state of the parent servers and restoring them we simply detach the servers (and clients) before the sending the clear and then re-attach.

    This simulates what I like to call a local clear which prevents the Clear method from propagating up-n-down the server structure. Something I have mentioned to DAW in the past and I believe would be a very useful addition to the DD methods.

    I'm happy to post the code if anyone is interested.
    Kind regards,

    Clive Richmond
    Triumph Business Systems Pty Ltd
    www.triumph.com.au

  10. #10
    Join Date
    Feb 2009
    Location
    Stord, Norway
    Posts
    882

    Default Re: Make a copy of the current record in a datadictionary object.

    Clive, I'm interested!
    Ola Eldøy (Twitter: @olaeld) - Developer at Emma EDB AS

Page 1 of 3 123 LastLast

Similar Threads

  1. Get DataDictionary Object from File Number
    By Leonard Slingerland in forum Windows Applications
    Replies: 6
    Last Post: 12-Apr-2011, 05:27 AM
  2. Help to make a copy of a record on screen
    By JAMES GREEN in forum Windows Applications
    Replies: 10
    Last Post: 30-Oct-2009, 09:25 AM
  3. how to make print the current record from the view
    By sushma@one-associates.com in forum Windows Applications
    Replies: 1
    Last Post: 29-Sep-2009, 04:13 AM
  4. Print WinReport Of Current Record
    By sushma@one-associates.com in forum Windows Applications
    Replies: 6
    Last Post: 15-Sep-2009, 08:12 AM
  5. Make a inactive copy of an existing record in DD
    By Paolo Bruno in forum Windows Applications
    Replies: 5
    Last Post: 30-Aug-2007, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •