Incompatible data type expression

Mkontwg

Member
Hi team

I have created this method with field variables declared and initialized
Code:
METHOD PROTECTED DataTable ProTTDataTable(queryHandle as HANDLE, fieldNames as CHARACTER):
        DEFINE VARIABLE listRecord AS System.Array NO-UNDO.
        DEFINE VARIABLE fieldHandle AS HANDLE NO-UNDO EXTENT.
        DEFINE VARIABLE fieldName AS HANDLE NO-UNDO.
        DEFINE VARIABLE bufferHandle AS HANDLE NO-UNDO.
        DEFINE VARIABLE i AS INTEGER NO-UNDO.
        DEFINE VARIABLE numFields AS INTEGER  NO-UNDO.
        DEFINE VARIABLE dataColumn AS DataColumn NO-UNDO.
        DEFINE VARIABLE dataTable AS DataTable NO-UNDO.
        
        
       
         assign(incompatible data type expression)
      bufferHandle = queryHandle:GET-BUFFER-HANDLE (1)
        dataTable = NEW DataTable(bufferHandle:NAME)
        numFields = (IF fieldName <> " " THEN NUM-ENTRIES (fieldName)ELSE bufferHandle:numFields)
        EXTENT(fieldHandle) = numFields
        listRecord = System.Array:CreateInstance(Progress.Util.TypeHelper:GetType("System.Object"), numFields).
        // condition for checking all entries in the table.
        
       do i = 1 to extent( fieldHandle ):
          assign
            fieldHandle[i] = ( if fieldnames <> "" then bufferHandle:buffer-field( entry( i, fieldNames )) else bufferHandle:buffer-field( i ))
            dataColumn = dataTable:Columns:Add( fieldHandle[i]:Name, DotNetType( fieldHandle[i]:Data-type ))  
            dataColumn:Caption = fieldHandle[i]:label.
            END.
            
            queryHandle:REPOSITION-TO-ROW (1).
            DO WHILE queryHandle:GET-NEXT: 
                DO i = 1 to EXTENT(fieldHandle):
                    listRecord:SetValue(fieldHandle[i]:BUFFER-VALUE, i - 1).
                    END.
                    dataTable:Rows:Add(listRecord).
                    END. 
        RETURN dataTable.
 END METHOD.
 

Osborne

Active Member
The incompatible data type expression usually means it cannot find the class you are referencing. This is either because the class/file is missing from the system or has to be added to the Assemblies file - assemblies.xml.

What is DataTable, is it a class you have created or is it part of the .NET component System.Data? If the latter try the following:

1) Using the Progress program Assembly References add System.Data from the Global Assemblies tab to the relevant assemblies.xml.
2) Ensure the session has access to the assemblies.xml file.
3) Prefix the relevant references with System.Data.:
Code:
METHOD PROTECTED System.Data.DataTable ProTTDataTable (queryHandle as HANDLE, fieldNames as CHARACTER):
        DEFINE VARIABLE dataColumn AS System.Data.DataColumn NO-UNDO.
        DEFINE VARIABLE dataTable AS System.Data.DataTable NO-UNDO.
        ...
 

Mkontwg

Member
The incompatible data type expression usually means it cannot find the class you are referencing. This is either because the class/file is missing from the system or has to be added to the Assemblies file - assemblies.xml.

What is DataTable, is it a class you have created or is it part of the .NET component System.Data? If the latter try the following:

1) Using the Progress program Assembly References add System.Data from the Global Assemblies tab to the relevant assemblies.xml.
2) Ensure the session has access to the assemblies.xml file.
3) Prefix the relevant references with System.Data.:
Code:
METHOD PROTECTED System.Data.DataTable ProTTDataTable (queryHandle as HANDLE, fieldNames as CHARACTER):
        DEFINE VARIABLE dataColumn AS System.Data.DataColumn NO-UNDO.
        DEFINE VARIABLE dataTable AS System.Data.DataTable NO-UNDO.
        ...


yes its .Net component and I have just prefixed it as mentioned. No changes as yet on my code. What could I be missing, clean project and clear error from open edge.
 

Osborne

Active Member
Ignore my last post as was totally thinking of a different error. Is this line causing the error?:
Code:
numFields = (IF fieldName <> " " THEN NUM-ENTRIES (fieldName)ELSE bufferHandle:numFields).
fieldname is a HANDLE not a CHARACTER variable.

Also, bufferHandle:numFields is not correct as it should be:
Code:
bufferHandle:NUM-FIELDS
 

Osborne

Active Member
Yes, it would be helpful if it also showed the actual line as well.

When you use a single ASSIGN for multiple assigning of lines it indicates there is an error in the ASSIGN statement. The problem is the red circle and cross appears on the ASSIGN line only and does not highlight the actual lines causing the error.

The only option I know of is to temporary add a period to each line and the actual line(s) will be highlighted - see attached.
 

Attachments

  • AssignError.png
    AssignError.png
    26.7 KB · Views: 6
Top