如何: -=在DBGrid中实现自动填充文字的功能=- 帮我看看这段代码? (100分)

  • 主题发起人 主题发起人 nulk
  • 开始时间 开始时间
N

nulk

Unregistered / Unconfirmed
GUEST, unregistred user!
以下程序可以自动填充,但不能Post,谁帮忙完成。
----
type
Tmygrid =class(TCustomGrid);
。。。

function DBGridComplete(mDBGrid: TmyGrid; mItems: TStrings; mCase: Boolean = True): Boolean;
var
I, T: Integer;
vSubStr, S: string;
begin
Result := False;
if not Assigned(mDBGrid) then Exit;

vSubStr := mDBGrid.InplaceEditor.Text;
if not mCase then vSubStr := UpperCase(vSubStr);
for I := 0 to Pred(mItems.Count) do
begin
S := mItems;
if not mCase then S := UpperCase(S);
if (Pos(vSubStr, S) = 1) and (vSubStr <> S) then begin
T := Length(vSubStr);
mDBGrid.InplaceEditor.Text := mItems;
mDBGrid.InplaceEditor.SelStart := T;
mDBGrid.InplaceEditor.SelLength := Length(mItems) - T;
Result := True;
Break;
end;
end;
end;

procedure TForm3.FormCreate(Sender: TObject);
begin
DBGrid1.Columns[0].PickList.Add('中国');
DBGrid1.Columns[0].PickList.Add('中国人民');
DBGrid1.Columns[0].PickList.Add('中国人民代表大会');
end;

procedure TForm3.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key>47) and (key<91) then
DBGridComplete(tMyGrid(DBGrid1), DBGrid1.Columns[DBGrid1.SelectedIndex].PickList, False);
end;
 
很难吗?
 
意思不明確
 
就是要在DBGrid中:
像Execl的功能,如果输入过‘中华人民共和国’
以后只要输入‘中’字,会自动帮你在‘中’字后补充‘[red]华人民共和国[/red]’
 
这段代码看上去很眼熟,原产地在
http://kingron.myetang.com/zsfunc0n.htm
看到有人能够扩展其功能,感到很高兴
发送一个按键信息给这个编辑框即可
比如:
SendKey('1');
SendKey('BACK');
 
zswang大侠,就是在那里找到的,是你写的?感谢!
关于“中文不完全输入”我一直想完成,无奈水平低无办法
哪位可以出手帮一帮?
 
//参考如下代码,Delphi6调试通过

function GetDBGridEdit(mDBGrid: TDBGrid): TEdit;
var
I: Integer;
begin
Result := nil;
if not Assigned(mDBGrid) then Exit;
if not mDBGrid.EditorMode then begin
mDBGrid.EditorMode := True;
mDBGrid.EditorMode := False;
end;
with mDBGrid do for I := 0 to Pred(ComponentCount) do
if Components is TCustomEdit then begin
Result := TEdit(Components);
Break;
end;
end; { GetDBGridEdit }

function DBGridComplete(mDBGrid: TDBGrid; mItems: TStrings;
mCase: Boolean = True): Boolean;
var
I, T: Integer;
vSubStr, S: string;
vEdit: TEdit;
begin
Result := False;
vEdit := GetDBGridEdit(mDBGrid);
if not (Assigned(vEdit)) then Exit;
vSubStr := vEdit.Text;
if vSubStr = '' then Exit;
if not mCase then vSubStr := UpperCase(vSubStr);
for I := 0 to Pred(mItems.Count) do begin
S := mItems;
if not mCase then S := UpperCase(S);
if (Pos(vSubStr, S) = 1) and (vSubStr <> S) then begin
T := Length(vSubStr);
vEdit.Text := mItems;
///////Begin 模拟按键
vEdit.SelStart := Length(S);
vEdit.Perform(WM_CHAR, Ord('?'), 0);
vEdit.Perform(WM_CHAR, 8, 0); //退格
///////End 模拟按键
vEdit.SelStart := T;
vEdit.SelLength := Length(mItems) - T;
Result := True;
Break;
end;
end;
end;

procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
{ VK_0 thru VK_9 are the same as ASCII '0' thru '9' ($30 - $39) }
{ VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' ($41 - $5A) }
VK_SPACE, VK_RETURN, $30..$5A: DBGridComplete(TDBGrid(Sender),
TDBGrid(Sender).Columns[TDBGrid(Sender).SelectedIndex].PickList, False);
end;
end;
 
接受答案了。
 
后退
顶部