Programming with Framework EDI .NET Hybrid
Set

The .Set method is the recommended method of assigning objects in Framework EDI .NET hybrid.  It is available in all FREDI .NET classes.

Syntax:

Returns:

Returns the object of the specified class type in the assignment.  The object returned contains new data returned from the object parameter object var2.

Remarks:

FREDI .NET hybrid is currently managed code wrapping unmanaged code.  In the .NET environment, the garbage collector can only clean up managed code, so FREDI has to be responsible for cleaning up the unmanaged code.  When a FREDI .NET program exits, all unmanaged resources are eventually cleaned up, but while the program is executing, unmanaged resources have to be cleaned up occasionally to prevent accumulation of unused objects and consuming valuable memory resources.  This method enables the client to notify FREDI when old data is being overwritten by new data so that the old data and its unmanaged resources can be released and cleaned up when it becomes necessary.  In .NET environment, the Dispose() method is used to indicate that data can be released, and internally the Set() method has the old data call the Dispose() method so that it can be released.  You can view the Set() method as being equivalent to the following lines of code in VB.NET when using the Dispose() method.

Using the .Set() method in the following code..

Dim oEdiDoc As ediDocument
Dim oSegment As ediDataSegment
:
ediDataSegment.Set(oSegment, oEdiDoc.FirstDataSegment())

.. is the same as the following code.

Dim oEdiDoc As ediDocument
Dim oSegment As ediDataSegment
:
If Not oSegment Is Nothing Then
    oSegment.Dispose()
End If
oSegment = oEdiDoc.FirstDataSegment()

When assigning from a pre-existing object variable like in the statement ..

    Set oSegment = oSegment.Next

.. the code looks as follows when using the .Set() method ..

Dim oEdiDoc As ediDocument
Dim oSegment As ediDataSegment
:
ediDataSegment.Set(oSegment, oEdiDoc.FirstDataSegment())

.. and is the same as the following code without using the .Set() method.

Dim oEdiDoc As ediDocument
Dim oSegment As ediDataSegment
Dim oSegment2 As ediDataSegment
:
If Not oSegment Is Nothing Then
    oSegment2 = oSegment.Next
    oSegment.Dispose()
End If
oSegment = oSegment2

 

For Visual Basic users, this method is similar to the Set statement where an existing object variable is being assigned data.

    Set oSegment = oSegment.Next

In VB.NET,

    ediDataSegment.Set(oSegment, oSegment.Next())

Example Syntax:

Dim oEdiDoc As ediDocument
Dim oSegment As ediDataSegment
Dim oSegment2 As ediDataSegment
:
' Do assignement
ediDataSegment.Set(oSegment, oSegment2)

Example:

Dim oEdiDoc As ediDocument
Dim oSchemas As ediSchemas
Dim oSchema As ediSchema
Dim oSegment As ediDataSegment

' Create instance of Framework EDI.
oEdiDoc = New ediDocument

oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly

' Disable standard reference library.
oSchemas = oEdiDoc.GetSchemas
oSchemas.EnableStandardReference = False

oSchema = oEdiDoc.LoadSchema(AppDomain.CurrentDomain.BaseDirectory & "SampleSefX12_850.SEF", 0)

' Load EDI document normally.
oEdiDoc.LoadEdi(AppDomain.CurrentDomain.BaseDirectory & "SampleEdiX12_850.X12")

oSegment = oEdiDoc.FirstDataSegment()

While Not oSegment Is Nothing

    Dim sSegmentID As String
    Dim sArea As String
    Dim sLoopSection As String

    sSegmentID = oSegment.ID
    sArea = oSegment.Area
    sLoopSection = oSegment.LoopSection

   ' Use the .Set method to let FREDI know that the client no longer
   ' needs the old data in oSegment. The new data returned
   ' by oSegment.Next will replace old data in oSegment.

    ediDataSegment.Set(oSegment, oSegment.Next())

End While

oEdiDoc.Dispose()

Samples