Ver Mensaje Individual
  #5  
Antiguo 10-06-2012
CrazySoft CrazySoft is offline
Miembro
 
Registrado: abr 2005
Posts: 100
Reputación: 22
CrazySoft Va por buen camino
Perdon lo que quiero es que se evalue automaticamte la expresion que le de y me almacene solo el valor no la expresion, lo que hice hasta el momento es usar el componente CalcExpress, y un edit que lo inclui al DBGrid, mi problema esta en que no puedo salir de la celda con las teclas de cursor o una ves terminado de editar

lo que hice fue a un dbgrid

Código Delphi [-]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked: array[Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
Begin
        if (Column.Field.FieldName = 'Expresion') then
            with Expresion do begin
                Left := Rect.Left + DBGrid1.Left + 1;
                Top := Rect.Top + DBGrid1.Top + 1;
                Width := Rect.Right - Rect.Left + 2;
                Width := Rect.Right - Rect.Left + 2;
                Height := Rect.Bottom - Rect.Top + 2;
                text := FloatToStr(ADOTable1Expresion.Value);
                Visible := True;
            end;
end;

procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin

    if (DBGrid1.SelectedField.FieldName = 'Expresion') then Expresion.Visible := False;
end;

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
    if (key = Chr(9)) then Exit;

    if (DBGrid1.SelectedField.FieldName = 'Expresion')
        then
    begin
        Expresion.SetFocus;
        SendMessage(Expresion.Handle, WM_Char, word(Key), 0);
    end;

end;

procedure TForm1.ExpresionClick(Sender: TObject);
begin
    DBGrid1.DataSource.Edit;

end;
procedure TForm1.ExpresionKeyPress(Sender: TObject; var Key: Char);
var
    CalcExpress1: TCalcExpress;
    args: array[0..100] of extended;
begin
    if key = #13 then
    begin
        CalcExpress1 := TCalcExpress.Create(self);
        CalcExpress1.Formula := Expresion.text;

        if DBGrid1.DataSource.State in [dsEdit, dsInsert] then
            ADOTable1Expresion.Value := CalcExpress1.calc(args);

        Expresion.text := floattostr(CalcExpress1.calc(args));
        CalcExpress1.free;
    end;
end;


mas conctratmente aqui esta el ejemplo

http://crazy-soft.net/descargas/DBGridExpresion.rar

Gracias, o hay algun componente que me realice lo que estoy hacendo
Responder Con Cita