Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

I need to create a function that will drop a field from a table, but I am having problem to create this function due to the kind of the field.

The error is when I try to compare whether the DataType is equal FieldExpected.

Function (Table, Field : String; FieldExpected: TFieldType) : Boolean
Var
  TQ : TADOQuery;
  I  : Integer;
  Drop : Boolean;
Begin
  TQ := TADOQuery.Create(Nil);
  TQ.Connection := Fmenu.ADOConnection1;
  Drop := False;

  Try
    With TQ do
    Begin
      Close;
      Sql.Add('SELECT * FROM ' + Table);
      Open;

      For I := 0 to Pred(TQ.Fields.Count) do
      Begin
        If TQ.Fields.Fields[I].FieldName = FieldThen
           Begin
             If Not TQ.Fields.Fields[I].DataType = FieldExpected Then
                Begin
                  Drop := True;
                End
             Else
                Begin
                  Drop := False;
                End
            Break
           End;
      End;
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

Thks