偶写的第一个控件,一个用选择代替输入的Edit控件…

2008-04-09 04:21:11来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


key:=0;
end;
end;
end;

//判断是否全是数字
function IsAllInteger(Text:widestring):boolean;
var
Temp:string;
i:integer;
begin
try
Result:=true;
Temp:=trim(text);
if (length(Temp)<=0) then
begin
Result:=false;
exit;
end;
for i:=1 to length(Temp) do
begin
if not (Temp[i] in [''''0''''..''''9'''']) then
begin
Result:=false;
break;
end;
end;
except
Result:=false;
end;
end;

//生成筛选语句
function CSQL(EditText,FieldName:WideString):WideString;
var
i:integer;
sql:WideString;
tmEditText1,tmEditText2:WideString;
begin
Result:='''''''';
if IsAllInteger(EditText) then
begin
tmEditText1:=trim(EditText);
tmEditText2:=trim(EditText);
SQL:=SQL ''''('''' FieldName ''''>='''' trim(EditText) '''' and '''' FieldName ''''<='''' inttostr((StrToInt(EditText) div 10)*10 9) '''')'''';
for i:=length(EditText) to 6 do
begin
tmEditText1:=tmEditText1 ''''0'''';
tmEditText2:=tmEditText2 ''''9'''';
sql:=sql '''' or ('''' FieldName ''''>='''' tmEditText1 '''' and '''' FieldName ''''<='''' tmEditText2 '''')'''';
end;
Result:=sql;
end;
end;

procedure TDBLookUpEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if FDBGrid.Visible then
begin
if (key=38) or (key=40) then
begin
SetRecText(1);
end
else if IsAllInteger(self.Text) then
begin
FADOQuery.Filtered:=false;
FADOQuery.Filter:=CSQL(self.Text,FKeyField);
FADOQuery.Filtered:=true;
end;
end;
end;

procedure TDBLookUpEdit.KeyPress(var Key: Char);
begin
inherited;
end;

function TDBLookUpEdit.GetConnection: TADOConnection;
begin
Result := FADOQuery.Connection;
end;

procedure TDBLookUpEdit.SetConnection(const Value: TADOConnection);
begin
if Value <> FADOQuery.Connection then
begin
FADOQuery.Connection := Value;
end;
if Value <> nil then Value.FreeNotification(Self);
end;

function TDBLookUpEdit.GetConnectionString: WideString;
begin
Result := FADOQuery.ConnectionString;
end;

procedure TDBLookUpEdit.SetConnectionString(const Value: WideString);
begin
if Value <> FADOQuery.ConnectionString then FADOQuery.ConnectionString := Value;
end;

function TDBLookUpEdit.GetActive: Boolean;
begin
Result :=FADOQuery.Active;
end;

procedure TDBLookUpEdit.SetActive(Value: Boolean);
begin
if Value <> FADOQuery.Active then
begin
FADOQuery.Active := Value;
end;
end;

function TDBLookUpEdit.GetSQL: TStrings;
begin
Result := FADOQuery.SQL;
end;

procedure TDBLookUpEdit.SetSQL(const Value: TStrings);
begin
if FADOQuery.SQL<>Value then FADOQuery.SQL.Assign(Value);
end;

procedure TDBLookUpEdit.Loaded;
begin
inherited Loaded;
end;

end.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:编译原理的一个简单的枚举算法

下一篇:delphi7的新特性