cannot retrieve the fieldname in the TDBFieldGetProperties

This forum contains all information about TDBAccess library for NHL 2004 roster access and general NHL coding questions.

Moderator: Owen

Post Reply
Goodspeed

cannot retrieve the fieldname in the TDBFieldGetProperties

Post by Goodspeed » Fri Dec 02, 2005 9:18 am

the code is
-----------------------------------------------------------------------------
table_name = TDBFieldGetProperties(0, "BSCS", 4, FieldProperties)

MsgBox FieldProperties.Name & "-" & FieldProperties.FieldType & "-" & FieldProperties.Size
-----------------------------------------------------------------------------

and the data Structure is

Type TdbFieldProperties
Name As String
Size As Integer
FieldType As TdbFieldType
End Type

Enum TdbFieldType
tdbString = 0
tdbBinary = 1
tdbSInt = 2
tdbUInt = 3
tdbFloat = 4
tdbInt = &H2CE
End Enum


can any body tell me where i m wrong

Mediator88
Posts: 71
Joined: Tue Nov 25, 2003 9:08 am
Location: Bethlehem, PA
Contact:

Post by Mediator88 » Sun Dec 04, 2005 12:51 pm

IF you're working in VB.NET, you need to initialize the string portion of the field types property with something.

Try adding FieldProperties.Name = Space(4) before calling the GetTableProperties.

Brian

Artem
Site Admin
Posts: 1166
Joined: Thu Oct 23, 2003 5:30 pm

Post by Artem » Sat Dec 17, 2005 1:21 pm

I'm not sure, I think this needs to be done in VB6 as well (see iam's problem).

I'll update the documentation for tdbaccess during the next update to include this information.

loken
Posts: 6
Joined: Tue Jun 27, 2006 8:32 pm

Post by loken » Wed Jun 28, 2006 3:45 pm

Code: Select all

procedure TForm1.BitBtn2Click(Sender: TObject);
var
   TableName: array [0..4] of Char;    // This variable will be the buffer of the table name
   CurTableProp: TtdbTableProperties;
   CurFldProp: TtdbFieldProperties;

   DBIdent, x: LongInt;
   Buf: array of char;

begin

   // Open database
   DBIdent := TDBOpen('zzTest.dyn');

   //Clean out the FldProp Structure
   CurFldProp.Name := '    ';
   CurFldProp.Size := 0;
   CurFldProp.FieldType := tdbString;

   if DBIdent <> -1 then
   begin
     // Assign to Name member the address of our buffer
     CurTableProp.Name := TableName;

     // Get Table properties
     if TDBTableGetProperties(DBIdent, 3, CurTableProp) then
     begin
       for x := 0 to CurTableProp.FieldCount do
       begin
           if TDBFieldGetProperties(DBIdent, TableName, 1, CurFldProp) then
             memo1.lines.add(CurFldProp.Name ); //Place the Fld Name in the memobox 
       end;
     end;

     // Close the database
     TDBClose(DBIdent);

end;
I am having a simular issue with Delphi when the compiler trys to call TDBFieldGetProperties(DBIdent, TableName, 1, CurFldProp) the .dll generates an access violation. I copied the structures straight from the documentation.

Any ideas?

Thanks
George

Artem
Site Admin
Posts: 1166
Joined: Thu Oct 23, 2003 5:30 pm

Post by Artem » Wed Jun 28, 2006 7:39 pm

You for-loop ending index is out of range. The correct way would be

Code: Select all

for x := 0 to CurTableProp.FieldCount - 1 do

loken
Posts: 6
Joined: Tue Jun 27, 2006 8:32 pm

Post by loken » Wed Jun 28, 2006 11:09 pm

I wish that was all it was (but I did miss it). I specifically changed the code removing x before even posting it...TDBFieldGetProperties(DBIdent, TableName, 1, CurFldProp)....by staticly placing my "1" in the call all that should happen is I should get is "AGMU" (the first column name in the GMDA table) 50 times (actually 51 times because of my miscoding).

Artem
Site Admin
Posts: 1166
Joined: Thu Oct 23, 2003 5:30 pm

Post by Artem » Sat Jul 15, 2006 6:11 pm

Did you solve the problem?

One other guess i have is using a constant empty string to assign Name field. Try using something like StrAlloc or assign the array like you did with table name.

loken
Posts: 6
Joined: Tue Jun 27, 2006 8:32 pm

Post by loken » Mon Jul 24, 2006 1:56 pm

Unfortuantley no I never did get the TDBFieldGetProperties working. I will try your suggestion.

loken
Posts: 6
Joined: Tue Jun 27, 2006 8:32 pm

Post by loken » Mon Jul 24, 2006 4:28 pm

Thanks it worked. Now to try and deciper the fields and tables.

adqttr
Posts: 1
Joined: Fri Apr 01, 2011 11:24 am

Re: cannot retrieve the fieldname in the TDBFieldGetProperti

Post by adqttr » Fri Apr 01, 2011 11:27 am

I am having this exact problem, I am even declaring the name field ahead of time, and nothing in the field properties ever changes. I am wondering how you ever solved this.

I am using visual studio and vb.net, is this a problem? The Table properties works, and the field properties is used byref the same way table properties is.

Code: Select all

Declare Function TDBOpen Lib "tdbaccess.dll" (ByVal FileName As String) As Integer
    Declare Function TDBClose Lib "tdbaccess.dll" (ByVal DBIndex As Integer) As Boolean
    Declare Function TDBTableGetProperties Lib "tdbaccess.dll" (ByVal DBIndex As Integer, ByVal FieldIndex As Integer, ByRef TableProperties As TdbTableProperties) As Boolean
    Declare Function TDBDatabaseGetTableCount Lib "tdbaccess.dll" (ByVal DBIndex As Integer) As Integer
    Declare Function TDBDatabaseGetTableCount Lib "tdbaccess.dll" (ByVal DBIndex As Integer, ByVal TableName As String, ByVal FieldIndex As Integer, ByRef FieldProperties As TdbFieldProperties) As Boolean
    Declare Function TDBTableRecordAdd Lib "tdbaccess.dll" (ByVal DBIndex As Integer, ByVal TableName As String, ByVal AllowExpand As Boolean) As Integer
    Declare Function TDBFieldGetValueAsString Lib "tdbaccess.dll" (ByVal DBIndex As Integer, ByVal TableName As String, ByVal FieldName As String, ByVal RecNo As Integer, ByRef OutBuffer As String) As Boolean

    Sub Main()
        Dim DBHandle As Integer
        Dim CurTableProps As TdbTableProperties
        Dim CurFieldProps As TdbFieldProperties
        Dim TableCount As Integer
        Dim FieldIndex As Integer
        Dim Index As Integer
        'We need to initialize Name buffer to receive the table name  
        CurTableProps.Name = "1234567890"
        CurFieldProps.Name = "1"

        DBHandle = TDBOpen("Files\exhibition.exh")
        If DBHandle <> -1 Then
            TableCount = TDBDatabaseGetTableCount(DBHandle)
            Console.WriteLine("Table Count is : " & TableCount)
            For Index = 0 To (TableCount - 1)
                'Read table properties  
                If TDBTableGetProperties(DBHandle, Index, CurTableProps) Then
                    'Display table name and the number of records  
                    Console.WriteLine(CurTableProps.Name & " : " & CStr(CurTableProps.RecordCount) & " records")
                    For FieldIndex = 0 To (CurTableProps.FieldCount)
                        If TDBDatabaseGetTableCount(DBHandle, CurTableProps.Name, 1, CurFieldProps) Then
                            Console.Write(":F:" & CurFieldProps.Name)
                        End If
                    Next
                    Console.WriteLine("")
                End If
            Next

            'Close the database  
            TDBClose(DBHandle)
        End If

        Console.ReadKey()

    End Sub

    Structure TdbTableProperties
        Public Name As String
        Public FieldCount As Integer
        Public Capacity As Integer
        Public RecordCount As Integer
        Public DeletedCount As Integer
        Public NextDeletedRecord As Integer
        Public Flag0 As Boolean
        Public Flag1 As Boolean
        Public Flag2 As Boolean
        Public Flag3 As Boolean
        Public NonAllocated As Boolean
    End Structure

    Structure TdbFieldProperties
        Public Name As String
        Public Size As Integer
        Public FieldType As TdbFieldType
    End Structure

    Enum TdbFieldType
        tdbString = 0
        tdbBinary = 1
        tdbSInt = 2
        tdbUInt = 3
        tdbFloat = 4
        tdbInt = &H2CE
    End Enum
I know this is probably mostly dead, but if there is anyone out there, please help me. Thanks!

Post Reply