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
[-]
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
begin
end; 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;
procedure TForm1.ADOTable1DebeGetText(Sender: TField; var Text: string;
DisplayText: Boolean);
begin
Text := floattostr(CalcularExpresion(TField(Sender).AsString));
end;
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