Recent

Author Topic: [SOLVED] TDBF Retrieve typ of fiield  (Read 1041 times)

bourbon

  • New Member
  • *
  • Posts: 11
[SOLVED] TDBF Retrieve typ of fiield
« on: October 25, 2024, 06:09:56 pm »
Hello,
I want to update a file that has a date saved in ftString format.
I created a new file with the date in ftDate format.
I am writing a program that will read the first file and write to the new file with the new date format.
I am not the one who will use this program.
You have to select the old and new files via an opendialog. To make sure that there is no inversion in the opening of the files, I want to test the date field type of the two files. The first (Ann_Old), must be of type ftString, and the second (Ann_New) must be of type ftDate)

For the test, I use the following code:
Code: Pascal  [Select][+][-]
  1. if (Ann_New.FieldDefs[16].DataType = ftString) then

The completion passes, but I cannot use the result.
« Last Edit: October 26, 2024, 09:35:00 am by bourbon »

wp

  • Hero Member
  • *****
  • Posts: 12530
Re: TDBF Retrieve typ of fiield
« Reply #1 on: October 25, 2024, 07:44:11 pm »
Is index 16 correct? Rather than referring to a field by its index it would be safer to refer to it by the fieldname:
Code: Pascal  [Select][+][-]
  1.  if (Ann_New.FieldByName('Birthdate') = ftString) then

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TDBF Retrieve typ of fiield
« Reply #2 on: October 25, 2024, 08:11:52 pm »
The completion passes, but I cannot use the result.
And what does 'I cannot use the result'?
Why can't you use the result?

(Maybe show some more code as to how you use that result and why it's 'wrong'.)

bourbon

  • New Member
  • *
  • Posts: 11
Re: TDBF Retrieve typ of fiield
« Reply #3 on: October 26, 2024, 09:34:07 am »
Depending on the type of fields, and if it is not the right type, I display an error message (and I close the file)
But to test and despite the fact that I intentionally open the wrong file, I do not have a message that is displayed.
Is index 16 correct? Rather than referring to a field by its index it would be safer to refer to it by the fieldname:
Code: Pascal  [Select][+][-]
  1.  if (Ann_New.FieldByName('Birthdate') = ftString) then
I also tested this coding, without result.

Yes, there are 17 fields in this file, and it is the last field.
I had found several codes on the internet to solve this problem, but none of them could work correctly. Either they generate a crash, or nothing happens.

I finally found the solution:
Code: Pascal  [Select][+][-]
  1.    if (Ann_Old.FieldDefs.Items[16].DataType = ftDate) then
I can now decide based on the result of this test.
Thanks for your advice.


wp

  • Hero Member
  • *****
  • Posts: 12530
Re: TDBF Retrieve typ of fiield
« Reply #4 on: October 26, 2024, 10:59:16 am »
I had found several codes on the internet to solve this problem, but none of them could work correctly. Either they generate a crash, or nothing happens.
Can you post a link to one or two of them? I cannot imagine why a comparison of field.DataType against ftDate should work, but against ftString should not.

gidesa

  • Full Member
  • ***
  • Posts: 156
Re: [SOLVED] TDBF Retrieve typ of fiield
« Reply #5 on: October 26, 2024, 01:19:16 pm »

Code: Pascal  [Select][+][-]
  1. if (Ann_New.FieldDefs[16].DataType = ftString) then
There are many types of "string" in database fields, apart ftString, at less: ftFixedChar, ftWideString, ftMemo.
This is  the complete list of all field types from Delphi doc, you can verify in debug the datatype of that field and find the exact constant:
Code: Pascal  [Select][+][-]
  1. type TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord, ftBoolean, ftFloat, ftCurrency,
  2.  ftBCD, ftDate, ftTime, ftDateTime, ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
  3. ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar, ftWideString, ftLargeint, ftADT, ftArray,
  4. ftReference, ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface, ftIDispatch, ftGuid, ftTimeStamp,
  5. ftFMTBcd, ftFixedWideChar, ftWideMemo, ftOraTimeStamp, ftOraInterval, ftLongWord, ftShortint, ftByte, ftExtended,
  6. ftConnection, ftParams, ftStream, ftTimeStampOffset, ftObject, ftSingle)
« Last Edit: October 26, 2024, 01:28:04 pm by gidesa »

bourbon

  • New Member
  • *
  • Posts: 11
Re: TDBF Retrieve typ of fiield
« Reply #6 on: November 07, 2024, 09:38:45 am »
Can you post a link to one or two of them? I cannot imagine why a comparison of field.DataType against ftDate should work, but against ftString should not.

Whether I test a date field or a string field, I had the same problem. It works fine with the solution I gave.

 

TinyPortal © 2005-2018