Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 17-08-2012
CrazySoft CrazySoft is offline
Miembro
 
Registrado: abr 2005
Posts: 100
Poder: 22
CrazySoft Va por buen camino
hola ecfisa, mira sigo con el problema el error me sale antes del GetText, y no pe permite ingresar * o / en el DBGrid,

estoy usando D6 y Access para el ejemplo y tambien probe con FB , y me sa el mismo error

Código Delphi [-]

// Tedit añadido para el calculo en la expresion en el campo expresio que es de tipo numerico no funciona muy bien 

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);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
  if (gdFocused in State) then
    begin

      if (Column.Field.FieldName = 'Expresion') then
        with Expresion do
          begin
            text := FloattoStr(Column.Field.asfloat);

            Left := Rect.Left + DBGrid1.Left + 1;
            Top := Rect.Top + DBGrid1.Top + 1;
            Width := Rect.Right - Rect.Left + 2;
            Height := Rect.Bottom - Rect.Top + 2;
            Visible := True;

          end;
    end
  else {in this else area draw any "stay behind" bitmaps}
    begin
    end; //if focused
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i, j: Integer;
begin
  AdoTable1.Active := True;

  with DBGrid1.DataSource.DataSet do
    for i := 0 to DBGrid1.FieldCount - 1 do
      for j := 0 to FieldCount - 1 do
        if Fields[j].FieldName = DBGrid1.Fields[i].FieldName then
          DBGrid1.Columns[i].Title.Alignment := Fields[j].Alignment;

  DBGrid1.Align := alClient;


  Expresion.Visible := False;

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.ExpresionKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
  Begin
  DBGrid1.DataSource.Edit;
  ExpresionExit(self);
  end;
end;

procedure TForm1.ExpresionExit(Sender: TObject);
begin
  if DBGrid1.DataSource.State in [dsEdit, dsInsert] then
  Begin
    ADOTable1Expresion.Value := CalcularExpresion(Expresion.text);
    Expresion.text  :=ADOTable1Expresion.text;
  end;
end;

function TForm1.CalcularExpresion(Expre: string): Real;
var
  CalcExpress1: TCalcExpress;
  args: array[0..100] of extended;
begin

  CalcExpress1 := TCalcExpress.Create(self);
  CalcExpress1.Formula := Expre;
  result := CalcExpress1.calc(args);
  CalcExpress1.free;

end;

function CalcularExpresionX(Expre: string): Double;
begin
  Result := StrToFloat(Expre)*2;
end;


// este es un campo de tipo numerico,  me da error antes de llegar a este punto me da error 5-2 no es valor de punto flotantes y no me permite ingresar 6/4 

procedure TForm1.ADOTable1DebeGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);

begin

     Text := floattostr(CalcularExpresion(TField(Sender).AsString));
//     Text := floattostr(CalcularExpresion(FloatToStr(TField(Sender).AsFloat)));
//     Text := floattostr(CalcularExpresion(TField(Sender).Value));

end;


// este es un campo de tipo texto,  y funciona todo correctamente pero necesito que sea numerico
 
procedure TForm1.ADOTable1TitleGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
     Text := floattostr(CalcularExpresion(TField(Sender).asstring));

end;

adjunto el ejemplo que estoy hacendo

Gracias, por la ayuda
Imágenes Adjuntas
Tipo de Archivo: png grid calcu.png (1,3 KB, 2 visitas)
Archivos Adjuntos
Tipo de Archivo: rar DBGrid.rar (22,6 KB, 3 visitas)
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
¿Como calcular un campo basado en otro campo de otra fila (registro)? AzidRain MySQL 9 19-12-2011 11:34:42
calcular campo josi Varios 1 22-08-2008 18:20:43
TQuery y calcular campo HombreGordo Conexión con bases de datos 13 08-08-2008 17:51:25
Calcular el total de un campo efelix MS SQL Server 2 16-01-2007 23:56:11
Calcular Campo calculado solo una vez mambo5cu Tablas planas 3 16-03-2005 22:38:59


La franja horaria es GMT +2. Ahora son las 22:51:04.


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