Delphi是Borland公司開發(fā)的可視化開發(fā)系統(tǒng),它基于Windows 95/98/NT,采用高度結(jié)構(gòu)化的Object Pascal語言,具有結(jié)構(gòu)清晰、高效優(yōu)化的特點(diǎn)。尤其,最新版Delphi5.0更以其良好的可視化應(yīng)用程序開發(fā)環(huán)境以及其強(qiáng)大的可擴(kuò)展數(shù)據(jù)庫功能而倍受廣大編程愛好者和專業(yè)程序員青睞。在編程界流行的“真正的程序員用VC, 聰明的程序員用Delphi”之說,足見其為大家認(rèn)可的程度。
現(xiàn)將收集的Delphi常用技巧收錄如下,以享廣大Delphi愛好者:
輸入處理篇
1. 獲取鍵盤滾動鎖, 插入態(tài), 大寫鎖, 數(shù)字鎖的開關(guān)狀態(tài) //Virtual =Vk_Scroll或Vk_capital或Vk_NUMLock或Vk_Insert
function FuncKeyOn(VirtualKey: Word): Boolean;
begin
Result := Bool(GetKeyState(VirtualKey) and 1);
end;
2. 當(dāng)用戶按下Enter/Up/Down鍵時使焦點(diǎn)切換到下一個聚焦對象
//設(shè)置窗體的KeyPriview屬性為True, 并寫入如下代碼: procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
SendMessage(Handle, WM_NEXTDLGCTL, 0, 0);
Key := #0;
end;
end;
procedure
TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Begin
If Key=Vk_Up then SendMessage(Handle, Wm_NextDlgCtl, 1, 0);
If Key=Vk_Down then SendMessage(Handle, Wm_NextDlgCtl, 0, 0);
end;
3. 取得鼠標(biāo)的絕對位置和設(shè)置鼠標(biāo)的絕對位置 function GetMousePos: Tpoint;
Begin
GetCursorPos(ThePoint);
End;
Procedure SetMousePos(X, Y: Word);;
var
Tp: Tpoint;
begin
Tp := ClientToScreen(Point(x, y));
SetCursorPos(tp.x, tp.y);
現(xiàn)將收集的Delphi常用技巧收錄如下,以享廣大Delphi愛好者:
輸入處理篇
1. 獲取鍵盤滾動鎖, 插入態(tài), 大寫鎖, 數(shù)字鎖的開關(guān)狀態(tài) //Virtual =Vk_Scroll或Vk_capital或Vk_NUMLock或Vk_Insert
function FuncKeyOn(VirtualKey: Word): Boolean;
begin
Result := Bool(GetKeyState(VirtualKey) and 1);
end;
2. 當(dāng)用戶按下Enter/Up/Down鍵時使焦點(diǎn)切換到下一個聚焦對象
//設(shè)置窗體的KeyPriview屬性為True, 并寫入如下代碼: procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
SendMessage(Handle, WM_NEXTDLGCTL, 0, 0);
Key := #0;
end;
end;
procedure
TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Begin
If Key=Vk_Up then SendMessage(Handle, Wm_NextDlgCtl, 1, 0);
If Key=Vk_Down then SendMessage(Handle, Wm_NextDlgCtl, 0, 0);
end;
3. 取得鼠標(biāo)的絕對位置和設(shè)置鼠標(biāo)的絕對位置 function GetMousePos: Tpoint;
Begin
GetCursorPos(ThePoint);
End;
Procedure SetMousePos(X, Y: Word);;
var
Tp: Tpoint;
begin
Tp := ClientToScreen(Point(x, y));
SetCursorPos(tp.x, tp.y);