Criar Tabela Paradox - Delphi


Exemplo de como criar uma tabela paradox em tempo de execução no delphi com chaves primárias e segundárias:

 

// Tabela: 'CADFOR'

  with TTable.Create(Application) do
  begin
    try
      TableName := 'CadFOR';
      DatabaseName := 'MeuAlias';
      TableType := ttParadox;

      if not Exists then
      begin
        with FieldDefs do
        begin
          Clear;
          Add('CODIGOFOR', ftAutoInc, 0, False);
          Add('RAZAOFOR', ftString, 60, False);
          Add('FANTASIAFOR', ftString, 40, False);
          Add('CGCCPFFOR', ftString, 20, False);
          Add('IERGFOR', ftString, 20, False);
          Add('ENDFOR', ftString, 50, False);
          Add('COMPLFOR', ftString, 20, False);
          Add('CIDFOR', ftString, 40, False);
          Add('CEPFOR', ftString, 10, False);
          Add('UFFOR', ftString, 2, False);
          Add('SITEFOR', ftString, 40, False);
          Add('DDDFOR', ftString, 3, False);
          Add('FONE1FOR', ftString, 15, False);
          Add('FONE2FOR', ftString, 15, False);
          Add('FONE3FOR', ftString, 15, False);
          Add('FONE4FOR', ftString, 15, False);
          Add('CONTATOFOR', ftString, 30, False);
          Add('EMAILFOR', ftString, 40, False);
          Add('OBSFOR', ftMemo, 1, False);
        end;

        with IndexDefs do
        begin
          Clear;
          Add('', 'CODIGOFOR', [ixPrimary, ixUnique]);
          Add('CGCC', 'CGCCPFFOR', [ixCaseInsensitive]);
          Add('FANT', 'FANTASIAFOR', [ixCaseInsensitive]);
          Add('RAZA', 'RAZAOFOR', [ixCaseInsensitive]);
          Add('CODI', 'CODIGOFOR', [ixCaseInsensitive]);
        end;

        CreateTable;
      end;
    finally
      Free;
    end;
  end;

Comentários