Cary Jensen
Cary Jensen

Reputation: 3791

How to cast the Column_Attributes field returned by a TFDMetaInfoData when MetaDataType is mtTableFields?

When using TFDMetaInfoQuery with a MetaDataType of mtTableFields, the documentation says to cast the returning Column_Attributes field as a TFDDataAttributes type in order to examine the particular field's attributes, such as not required (caAllowNull) and caReadOnly. How exactly is this done? Consider the following code segment, which returns a table of data concerning the MyTable fields:

var
  FieldAttributes: TFDDataAttributes;
  Required: Boolean;
begin
  FDMetaInfoQuery1.MetaInfoKind := mkTableFields;
  FDMetaInfoQuery1.Open('MyTable'); 
  for i := 0 to FDMetaInfoQuery1.RecordCount -1  do
  begin   
    FieldAttributes := TFDDataAttributes(FDMetaInfoQuery1.FieldByName('Column_Attributes').AsExtended);
    // test for particular TFDDataAttribute flags in the TFDDataAttributes set
   // ie, if not  ( caAllowNull in FieldAttributes ) then // flag column as required
  end;

The line casting the Column_Attributes column generates a compiler error of Invalid typecast. I've tried getting the Column_Attributes fields as a variant, and several other types, but I keep getting the same error. By the way, the data type of the Column_Attributes column is dtUInt32. The FireDAC help says to "Cast value to FireDAC.Stan.Intf.TFDDataAttributes."

Suggestions?

Upvotes: 1

Views: 283

Answers (1)

dsonda
dsonda

Reputation: 71

I found the code below at http://docwiki.appmethod.com/appmethod/1.17/topics/en/Metadata_Structure_(FireDAC)

var
  i: Integer;
...
  i := FDMetaInfoQuery1.FieldByName('COLUMN_ATTRIBUTES').AsInteger;
  eAttrs := TFDDataAttributes(Pointer(@i)^);

Upvotes: 2

Related Questions