Ver Mensaje Individual
  #4  
Antiguo 25-09-2016
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
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 LACV.

Dos opciones, una usando el evento OnDrawColumnCell:
Código Delphi [-]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const
  SINO : array[0..1] of String = ('NO', 'SI');
var
  gr: TDBGrid;
  R : TRect;
  sw: LongWord;
begin
  if Column.FieldName = 'Campo_0_1' then
  begin
    case Column.Alignment of
      taLeftJustify  : sw := sw or DT_LEFT;
      taRightJustify : sw := sw or DT_RIGHT;
      taCenter       : sw := sw or DT_CENTER;
    end;
    R := Rect;
    gr := TDBGrid(Sender);
    gr.Canvas.FillRect(R);
    DrawText(gr.Canvas.Handle, PChar(SINO[Column.Field.AsInteger]), -1, R, sw);
  end;
end;

Otra usando el evento OnGetText del campo en cuestión:
Código Delphi [-]
...
procedure TForm1.FormCreate(Sender: TObject);  {1}
begin
  DataSet.FieldByName('Campo_0_1').OnGetText := DataSetCampo_0_1GetText;
end;

procedure TForm1.DataSetCampo_0_1GetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
const
  SINO : array[0..1] of String = ('NO', 'SI');
var
  v: Integer;
begin
  v := TField(Sender).AsInteger;
  if v in [0, 1] then
    Text := SINO[TField(Sender).AsInteger];
end;

...

procedure TForm1.FormDestroy(Sender: TObject); {2}
begin
  DataSet.FieldByName('Campo_0_1').OnGetText := nil;
end;
("Campo_0_1" sería el nombre del campo de tu tabla que almacena los valores enteros 0 y 1)

En la segunda opción podes ahorrarte los eventos {1} y {2} (y su código) si en tiempo de diseño creas los campos persistentes en el DataSet y asignas el evento OnGetText al campo desde el Object Inspector.

Saludos
__________________
Daniel Didriksen

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