1. 自己做个简单的解释器, 分析edit.text, 计算出结果添入数据库.
简单的例子: 比如输入: 1 2/3 表示1又3分之2.
edit1.onexit或者edit1.onkeydown(判断是否return键)中判断是否往数据库中写:
var
i: Integer;
n, n1:do
uble;
s: string;
begin
s := trim(edit1.text);
if s = '' then
// 出错;
i := 1;
n1 := 0;
while (i <= length(s)) and (s in ['0','1','2','3','4','5','6','7','8','9'])do
inc(i);
if i > 1 then
n := strtoint(copy(s, 1, i-1))
else
// 出错
delete(s, 1, i - 1);
s := trim(s);
if s[1] <> '/' then
begin
n1 := n;
i := 1;
while (i<=length(s)) and (s in ['0','1','2','3','4','5','6','7','8','9'])do
inc(i);
if i > 1 then
n := strtoint(copy(s, 1, i-1))
else
出错;
delete(s, 1, i-1);
end;
if (s <> '') and (s[1] = '/') then
n := n / strtointdef(copy(s, 2, length(s)), 1)
else
if (s <> '') then
//出错
table.edit;
table.fieldbyname('xxxx').asfloat := n+n1;
table.post;
end;
2. dbgrid1.onkeydown中写如下代码:
if (key = VK_RETURN) and dbgrid1.editormode then
begin
key := 0;
if dbgrid1.selectedindex < dbgrid1.fieldcount - 1 then
dbgrid1.selectedindex := dbgrid1.selectedindex + 1;
end;
3. 看不懂