View Single Post
  #1  
Old 26/06/2012
ecfisa's Avatar
ecfisa ecfisa is offline
Moderador
 
Join Date: Dec 2005
Location: Tres Arroyos, Argentina
Posts: 10,508
Rep Power: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Me quedé pensando que tal vez no deseabas crear un campo calculado sino uno permantente.

Podes hacerlo mediante un TQuery, por ejemplo:
Código Delphi [-]
procedure TForm1.CrearCampo(aFieldName, aType: string);
var
  i: Integer;
  Exists: Boolean;
begin
  Table1.Open;
  Exists:= False;
  for i:=0 to Table1.FieldDefs.Count-1 do
    Exists:= Table1.Fields[i].FieldName = aFieldName;
  if not Exists then
  begin
    Table1.Close;
    with Query1 do
    begin
      SQL.Text:= 'ALTER TABLE TU_TABLA ADD '+aFieldName+' '+aType;
      ExecSQL;
      Close;
    end;
  end;
  if not Table1.Active then
    Table1.Open;
end;

Llamada:
Código Delphi [-]
   CrearCampo('NUEVO', 'BOOLEAN');


Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Last edited by ecfisa : 26/06/2012 at 21:49. Reason: ortografía
Reply With Quote