Dynamic field problem in VirtualTable

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

Re: Dynamic field problem in VirtualTable

Post by tcflam » Thu 14 Mar 2013 14:36

Hi, the error is coming from field creating. And can TVirtualtable handle Unicode?

tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

Re: Dynamic field problem in VirtualTable

Post by tcflam » Thu 14 Mar 2013 15:16

I fixed the problem. But I need to hardcode the fieldtype that can't use dynamic define.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Dynamic field problem in VirtualTable

Post by AlexP » Thu 14 Mar 2013 15:28

Hello,

The "Invalid field size" error occurs on incorrect field length, for example:

Code: Select all

VirtualTable1.AddField('test', ftWideString, -1);
Please provide an example of creating your field

tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

Re: Dynamic field problem in VirtualTable

Post by tcflam » Thu 14 Mar 2013 15:34

I use the following code to solve the problem

if map_setting.FieldByName('map_del_attrib').AsString = 'ftWideString' then
poreport_buffer.AddField(map_setting.FieldByName('map_table_field').Value, ftWideString , map_setting.FieldByName('map_field_length').Value)
else
poreport_buffer.AddField(map_setting.FieldByName('map_table_field').Value, TFieldType(i) ,map_setting.FieldByName('map_field_length').Value);

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Dynamic field problem in VirtualTable

Post by AlexP » Thu 14 Mar 2013 16:17

Hello,

If, when adding a ftWideString field, you even use TFieldType(i) instead of explicit type specifying, such error doesn't occur. Please make sure that TFieldType(i) returns the correct ftWideString type.

tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

Re: Dynamic field problem in VirtualTable

Post by tcflam » Fri 15 Mar 2013 00:46

Thanks for your remind. But I already define ftWideString into array. It also got the error message. So I post my question in here.

const
FieldTypeStr: array [0..13] of string = ('ftUnknown', 'ftString', 'ftSmallint', 'ftInteger', 'ftWord',
'ftBoolean', 'ftFloat', 'ftCurrency', 'ftBCD', 'ftDate', 'ftTime', 'ftDateTime', 'ftMemo', 'ftWideString');

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Dynamic field problem in VirtualTable

Post by AlexP » Fri 15 Mar 2013 10:44

Hello,

If you are using the code I provided earlier, in addition to ftWideString in the FieldTypeStr array, you should add the other types that are in TFieldType (described in the Data.DB module) before the ftWideString type.
And in your case, on the map_setting.FieldByName('map_del_attrib') = ftWideString field value,the loop variable "I" will be 14, in this case, TFieldType(14) will return the ftAutoInc type, that causes the error.

tcflam
Posts: 58
Joined: Tue 01 Jan 2013 10:48

Re: Dynamic field problem in VirtualTable

Post by tcflam » Sat 16 Mar 2013 16:49

Yup. I'm using your earlier code. It should be 13 when I check the For loop "high(FieldTypeStr)". So I don't understand why you said "I" will return 14.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Dynamic field problem in VirtualTable

Post by AlexP » Mon 18 Mar 2013 10:49

Hello,

Yes. the loop variable will be really equal to 13, and not to 14. But independently on this, when attempting to retrieve the type by this index from TFieldType, you will retrieve an incorrect type, since in TFieldType the ftWideString type has the index 24. You should edit your constant array according to the TFieldType description in the Data.DB module:

Code: Select all

   TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord, // 0..4
    ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime, // 5..11
    ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo, // 12..18
    ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar, ftWideString, // 19..24
    ftLargeint, ftADT, ftArray, ftReference, ftDataSet, ftOraBlob, ftOraClob, // 25..31
    ftVariant, ftInterface, ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd, // 32..37
    ftFixedWideChar, ftWideMemo, ftOraTimeStamp, ftOraInterval, // 38..41
    ftLongWord, ftShortint, ftByte, ftExtended, ftConnection, ftParams, ftStream, //42..48
    ftTimeStampOffset, ftObject, ftSingle); //49..51

Post Reply