Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Tablas planas (https://www.clubdelphi.com/foros/forumdisplay.php?f=20)
-   -   Crear índice en runtime (https://www.clubdelphi.com/foros/showthread.php?t=27343)

Gabriel2 17-11-2005 21:26:50

Crear índice en runtime
 
Para crear una tabla paradox en tiempo de ejecución utilizó un código similar a este:

Código Delphi [-]
 procedure TForm1.Button1Click(Sender:TObject);
 begin 
   if not Table1.Exists then 
   begin 
     Table1.Active       := FALSE; 
     Table1.DatabaseName := 'Alias'; 
     Table1.TableType    := ttParadox; 
     Table1.TableName    := 'Nombre de la Tabla'; 
     with Table1.FieldDefs do 
     begin 
       Clear; 
       Add('IntegerField', ftInteger,  0, FALSE); 
       Add('StringField' , ftString , 30, FALSE); 
       Add('LogicalField', ftBoolean,  0, FALSE); 
       Add('FloatField'  , ftFloat  ,  0, FALSE); 
       Add('DateField'   , ftDate   ,  0, FALSE); 
       Add('TimeField'   , ftTime   ,  0, FALSE); 
     end; 
     Table1.CreateTable; 
   end; 
 end;
Lo que no he podido hacer es crear un índice... alguién sabe cómo...

roman 17-11-2005 21:46:22

Cita:

Empezado por Gabriel2
Lo que no he podido hacer es crear un índice... alguién sabe cómo...

Pues no sé, me da que Table.AddIndex ha de servir de algo.

// Saludos

Gabriel2 17-11-2005 22:19:00

Solución
 
Código:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Table1.Exists then
  begin
        Table1.Active          := FALSE;
        Table1.DatabaseName := 'C:\Directorio';
        Table1.TableType        := ttParadox;
        Table1.TableName        := 'Mi DB';
        with Table1.FieldDefs do
        begin
          Clear;
          Add('AutoInc', ftAutoInc,  0, true) ;
          Add('StringField' , ftString , 30, FALSE);
          Add('LogicalField', ftBoolean,  0, FALSE);
          Add('FloatField'  , ftFloat  ,  0, FALSE);
          Add('DateField'  , ftDate  ,  0, FALSE);
          Add('TimeField'  , ftTime  ,  0, FALSE);
  end;
  Table1.IndexDefs.Clear;
  Table1.IndexDefs.Add('', 'AutoInc', [ixPrimary]);
  Table1.CreateTable;
  end;
end;

Así me funcionó. Gracias...


La franja horaria es GMT +2. Ahora son las 15:15:29.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi