On Monday, November 22, 1999 12:00:00 AM UTC-8, Lygedas wrote:
> Hello,
>
> I collide with one problem which I very need to solve.
> In Table1 field A (type is string) I have value : "Table2.FieldByName("B")".
> So I want :
>
> var
> Field1, Field3 : String;
> Field2 : TField;
>
> begin
> Field1 : = Table1.FieldByName("A").Text;
> Field2 : = (here I want to convert string type to TField type)
> ?????????????????????????
> Field3 : = Field2.Value;
> Print Field3; 'I must see Table2 field B value
> end.
>
> I will be very appreciate in your help.
>
> Thanks.
>
> Lygedas
from Sam D. Hunt
You actually need three array structs to do what you are attempting.
using the following arrays... (see below arrays for continuation)
ARRAY 1:
FieldTypes: array [TFieldType] of String =
('ftUnknown', 'ftString', 'ftSmallint', 'ftInteger', 'ftWord', 'ftBoolean',
'ftFloat', 'ftCurrency', 'ftBCD', 'ftDate', 'ftTime', 'ftDateTime', 'ftBytes', 'ftVarBytes',
'ftAutoInc', 'ftBlob', 'ftMemo', 'ftGraphic', 'ftFmtMemo', 'ftParadoxOle', 'ftDBaseOle',
'ftTypedBinary', 'ftCursor', 'ftFixedChar', 'ftWideString', 'ftLargeint', 'ftADT', 'ftArray',
'ftReference', 'ftDataSet', 'ftOraBlob', 'ftOraClob', 'ftVariant', 'ftInterface', 'ftIDispatch',
'ftGuid', 'ftTimeStamp', 'ftFMTBcd', 'ftFixedWideChar', 'ftWideMemo', 'ftOraTimeStamp',
'ftOraInterval', 'ftLongWord', 'ftShortint', 'ftByte', 'ftExtended', 'ftConnection',
'ftParams', 'ftStream', 'ftTimeStampOffset', 'ftObject', 'ftSingle');
ARRAY 2:
sFieldTypes: array [1..52] of String =
('ftUnknown', 'ftString', 'ftSmallint', 'ftInteger', 'ftWord', 'ftBoolean',
'ftFloat', 'ftCurrency', 'ftBCD', 'ftDate', 'ftTime', 'ftDateTime', 'ftBytes', 'ftVarBytes',
'ftAutoInc', 'ftBlob', 'ftMemo', 'ftGraphic', 'ftFmtMemo', 'ftParadoxOle', 'ftDBaseOle',
'ftTypedBinary', 'ftCursor', 'ftFixedChar', 'ftWideString', 'ftLargeint', 'ftADT', 'ftArray',
'ftReference', 'ftDataSet', 'ftOraBlob', 'ftOraClob', 'ftVariant', 'ftInterface', 'ftIDispatch',
'ftGuid', 'ftTimeStamp', 'ftFMTBcd', 'ftFixedWideChar', 'ftWideMemo', 'ftOraTimeStamp',
'ftOraInterval', 'ftLongWord', 'ftShortint', 'ftByte', 'ftExtended', 'ftConnection',
'ftParams', 'ftStream', 'ftTimeStampOffset', 'ftObject', 'ftSingle');
ARRAY 3:
ftFieldTypes: array [1..52] of TFieldType =
(ftUnknown, ftString, ftSmallint, ftInteger, ftWord, ftBoolean,
ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime, ftBytes, ftVarBytes,
ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo, ftParadoxOle, ftDBaseOle,
ftTypedBinary, ftCursor, ftFixedChar, ftWideString, ftLargeint, ftADT, ftArray,
ftReference, ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface, ftIDispatch,
ftGuid, ftTimeStamp, ftFMTBcd, ftFixedWideChar, ftWideMemo, ftOraTimeStamp,
ftOraInterval, ftLongWord, ftShortint, ftByte, ftExtended, ftConnection,
ftParams, ftStream, ftTimeStampOffset, ftObject, ftSingle);
FIRST Step (using array 1):GET string name of the target TFieldType
sString := FieldTypes[MyTable.Fields[{field number}].DataType];
SECOND Step(using second array):
Step through sFieldTypes array until you find the value equal to sString in step 1.
Capture the sFieldTypes index in an integer, such as iIndex.
LAST Step (using array 3):
Your sString string value can be converted back to the original TFieldType thusly:
TFieldType := ftFieldTypes[iIndex];
This works great for me.
I use this strategy to get the field info from a table on a remote server over the internet and create a local copy in a TClientDataset. I then use the local client dataset to update the remote server using Indy 10 TCP client and server components. The only issue I haven't fully resolved is concurrency.
Good luck.
Sam Hunt