CFRONT question

Hi, Can anyone help with the following Delphi problem using cfront ocx control. The project compiles but when running the code, I get the following error; Internal error 9 in module 24. Contact your dealer if you need assistance. Here is the code when the form opens; procedure TfrmMain.FormCreate(Sender: TObject); var hTable, counter : integer; servername, nettype, company : string; begin servername := nfserver; nettype := ‘tcp’; company := ‘companyname’; with cfrontNF do begin ConnectServer(servername,nettype); showmessage(‘connecting …’); OpenCompany(company); OpenTable(hTable,50001); counter := cfrontNF.RecCount(hTable); showmessage('Counter = ’ + inttostr(counter)); end; end; Any ideas anyone? Regards

Hi Connull, I’m not familiar with Delphi, but you might want to check the Navision internal error 9 in module 24. Try the following link: I hope this helps you. Good luck, Bartel W. de Leeuw

Or this one: Good luck, Bartel W. de Leeuw

There are troumle with memory allocation. Wrong var or Cfront initialization or something kind of. Which line couses error? If ConnectServer, check Cfront initialization.

To all, thanks for all your valid comments. The connecting seems to be working now, but I’m now having trouble accessing a table. I think it’s something to do with the handles of the table? Does anyone have any code examples of simply opening a connection, opening a company, opening a table and then returning in a message box, just the first field name or first field value? Just something simple, preferably in VB or Delphi, but C or C++ would be fine - it’s just the examples in the documentation aren’t detailed enough. Many thanks again.

Sample from Excel:



Sub GetCustomerList()
    Dim flist As Variant
    Dim cflist As Variant
    Dim htab, hrec, tnr, fnr As Long
    Dim rez As Boolean
    Dim filtr As String

    fnr = 1
    cflist = 62
    Set CF = CreateObject("cfront.cfrontctrl.1")
    CF.StopOnAllExceptions = False
    Call CF.ConnectServer("navision", "tcp")
    If CF.Login("cf", "cf") Then
        Call CF.OpenCompany("NONE")
        Call CF.LastError
        htab = Opentab()
        hrec = CF.AllocRec(htab)
        Dim AC, AC2 As Range, rado As Boolean
        Set AC = ActiveSheet

        For Each AC2 In ActiveSheet.Range("A:A")
         If AC2.Row <> 1 Then
            If AC2.Cells.Value = "" Then Exit For
                Call CF.InitRec(htab, hrec)
            flist = AC2.Cells.Value
            Call CF.AssignField(htab, hrec, fnr, flist)
            rado = CF.FindRec(htab, hrec, "=")
            If rado Then
                AC.Cells(AC2.Row, 4).Value = CF.GetFieldData(htab, hrec, 2)
                filtr = AC.Cells(1, 2).Value
                Call CF.SetFilter(htab, 56, filtr)
                Call CF.CalcFields(htab, hrec, cflist)
                AC.Cells(AC2.Row, 2).Value = CF.GetFieldData(htab, hrec, 62)
                filtr = AC.Cells(1, 3).Value
                Call CF.SetFilter(htab, 56, filtr)
                Call CF.CalcFields(htab, hrec, cflist)
                AC.Cells(AC2.Row, 3).Value = CF.GetFieldData(htab, hrec, 62)
            End If
          End If
        Next AC2
        Call CF.FreeRec(hrec)
        Call CF.CloseTable(htab)
    End If
    Set CF = Nothing
End Sub

Function Opentab() As Long
; cf bug or what? OpenTable works only in this way in vb :(
    Call CF.OpenTable(Opentab, 18)
End Function

Again thanks to you all for your responses. To Dalius Brokevicius, many thanks for the sample code - it worked perfectly. Have you done alot of development using cfront? Anyway, thanks again.

It’s my favorite tool. I’m using more than 3 years. I have done navision database replicator with own protocol over TCP/IP cuple years ago. I have made some reports on Excel using CFront.

Dalius Brokevicius, I have a favour to ask - do you have any sample code for modifying or inserting of new records into Navision database via VBA. I need to update more than one field as well. Sorry to be a pain. :slight_smile: Regards

Sorry, but I don’t have any sample about modify/insert in vb. But have some code in C. There are used dll, not ocx. But it’s very similar. You can find some examples in cfront help (pdf).

	if (rnode) DBL_AssignField(htab,rec->hrec,NODEFIELD,DBL_Type_S32,&(rnode),sizeof(DBL_Type_S32));
        //assign fields primary key fields
	while (*(DWORD*)pdata)
		pdata = rec->WriteRecField(pdata);

        //modify fields
	if (rnode) DBL_AssignField(htab,rec->hrec,NODEFIELD,DBL_Type_S32,&(rnode),sizeof(DBL_Type_S32));
	while (*(DWORD*)tpdat)
		tpdat = rec->WriteRecField(tpdat);

	if (!DBL_ModifyRec(htab, rec->hrec))
		// insert rec
		if (!(type & NF_ONLYMODIFY))
			if (! DBL_InsertRec(htab, rec->hrec)) 	

Hi Dalius,


I have made some reports on Excel using CFront.

Can you let me know how do you do that?