历史上最全的delphi技巧集锦之二
16、SaveDialog1确认文件存不存在的办法?答:procedure TForm1.SaveDialog1CanClose(Sender: TObject; var CanClose: Boolean); begin if FileExists(SaveDialog1.FileName) then //如果文件已经存在 if MessageDlg('文件已经存在,保存吗?', mtConfirmation, , 0) <> mrYes then Button2.Click//如果选择了覆盖,则退出,否则,重新让用户选择文件 end; ==============================================================================17、正确关闭一个MDI子窗口?答:Delphi中MDI子窗口的关闭方式默认为缩小而不是关闭,所以当你单击子窗口右上角的关闭按钮时会发觉该子窗口只是最小化,而不是你预期的那样被关闭。解决办法是在子窗口的OnClose事件处理过程中加入如下代码,示例:procedure ChildForm.OnClose(Sender: TObject; var Action: TCloseAction);beginAction := caFree;end; Delphi为一个Form的关闭行为指定了四种方式,分别是:caNone 禁止Form被关闭 caHide Form不被关闭,但是被隐藏。被隐藏的Form仍然可以被程序访问。 caFree Form被关闭,并且释放其占用的资源。 caMinimize Form被最小化而不是被关闭,这是MDI子窗口的默认关闭行为。 ==============================================================================18、怎样记MDI子窗口不在母体运行时就被打开?答:在project下的options中forms里面除了form1外,其余的移到右边的框里,然后在调用显示的按钮下编写语句,以form2调用为例:form2:=Tform2.create(self);form2.show;==============================================================================19、限制FORM的大小答:在FORM私有声明部分加上如下一行: procedure WMGetMinMaxInfo( var Message:TWMGetMinMaxInfo message WM_GETMINMAXINFO; 在声明部分加上如下几行: procedure TForm1.WMGetMinMaxInfo( var Message :TWMGetMinMaxInfobegin with Message.MinMaxInfo^ dobeginptMaxSize.X := 200; {最大化时宽度}ptMaxSize.Y := 200; {最大化时高度}ptMaxPosition.X := 99; {最大化时左上角横坐标}ptMaxPosition.Y := 99; {最大化时左上角纵坐标}end;Message.Result := 0; {告诉Windows你改变了 minmaxinfo}inherited;end; ==============================================================================20、随机数生成法答:Randomize;rn:=inttostr(random(9999));rn1:=inttostr(random(9999));.....==============================================================================21、怎样把程序隐藏起来,在WINDOWS界面上没有显示??答:在application.run之前加入application.showmain:=false! ==============================================================================22、怎样将一个form1.free的form1窗体重新显示?答:form2:=TForm2.Create(application);form2.Show;如果你要创建的Form2窗体能嵌入一个Panel中,指定Parent:form2:=TForm2.Create(application);form2.Parent:=panel1;form2.Show;==============================================================================23、我想在bitbtn上设快捷按钮Esc,怎么办?答:procedure TForm1.BitBtn1KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);beginif key=27 thenapplication.Terminate;end; 设它的cancel属性为true就行了~~==============================================================================24、什么叫做托盘区?答:托盘区就是在windows的状态栏下方显示时钟、输入法状态的地方,要把你的程序显示在托盘区:下面是一个托盘类,只要把下面粘贴到文本文件中,改成TrayIcon.pas,使用时uses TrayIcon就可以了。先声明一个全局变量:var tray:TTrayNotifyIcon;然后在窗体的OnCreate事件中:tray:=TTrayNotifyIcon.Create(self);//将窗体创建为托盘tray.Icon:=application.Icon;//定义托盘的显示图标tray.IconVisible:=true;//托盘可见tray.PopupMenu:=popmenu;//给托盘定义一个右击时的弹出菜单tray.OnDblClick:=trayDblClick;//给托盘定义一个双击事件(当然要自己写了,不过多数情况只有一行,就是Form1.show);unit TrayIcon;interfaceuses Windows, SysUtils, Messages, ShellAPI, Classes, Graphics, Forms, Menus,StdCtrls, ExtCtrls;typeENotifyIconError = class(Exception);TTrayNotifyIcon = class(TComponent)privateFDefaultIcon: THandle;FIcon: TIcon;FHideTask: Boolean;FHint: string;FIconVisible: Boolean;FPopupMenu: TPopupMenu;FonClick: TNotifyEvent;FOnDblClick: TNotifyEvent;FNoShowClick: Boolean;FTimer: TTimer;Tnd: TNotifyIconData;procedure SetIcon(Value: TIcon);procedure SetHideTask(Value: Boolean);procedure SetHint(Value: string);procedure SetIconVisible(Value: Boolean);procedure SetPopupMenu(Value: TPopupMenu);procedure SendTrayMessage(Msg: DWORD; Flags: UINT);function ActiveIconHandle: THandle;procedure OnButtonTimer(Sender: TObject);protectedprocedure Loaded; override;procedure LoadDefaultIcon; virtual;procedure Notification(AComponent: TComponent;Operation: TOperation); override;publicconstructor Create(AOwner: TComponent); override;destructor Destroy; override;publishedproperty Icon: TIcon read FIcon write SetIcon;property HideTask: Boolean read FHideTask write SetHideTask default False;property Hint: String read FHint write SetHint;property IconVisible: Boolean read FIconVisible write SetIconVisible default False;property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;property onClick: TNotifyEvent read FonClick write FonClick;property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;end;implementation{ TIconManager }{ This class creates a hidden window which handles and routes }{ tray icon messages }typeTIconManager = classprivateFHWindow: HWnd;procedure TrayWndProc(var Message: TMessage);publicconstructor Create;destructor Destroy; override;property HWindow: HWnd read FHWindow write FHWindow;end;varIconMgr: TIconManager;DDGM_TRAYICON: Cardinal;constructor TIconManager.Create;beginFHWindow := AllocateHWnd(TrayWndProc);end;destructor TIconManager.Destroy;beginif FHWindow <> 0 then DeallocateHWnd(FHWindow);inherited Destroy;end;procedure TIconManager.TrayWndProc(var Message: TMessage);{ This allows us to handle all tray callback messages }{ from within the context of the component. }varPt: TPoint;TheIcon: TTrayNotifyIcon;beginwith Message dobegin{ if it’s the tray callback message }if (Msg = DDGM_TRAYICON) thenbeginTheIcon := TTrayNotifyIcon(WParam);case lParam of{ enable timer on first mouse down. }{ onClick will be fired by OnTimer method, provided }{ double click has not occurred. }WM_LBUTTONDOWN: TheIcon.FTimer.Enabled := True;{ Set no click flag on double click. This will supress }{ the single click. }WM_LBUTTONDBLCLK:beginTheIcon.FNoShowClick := True;if Assigned(TheIcon.FOnDblClick) then TheIcon.FOnDblClick(Self);end;WM_RBUTTONDOWN:beginif Assigned(TheIcon.FPopupMenu) thenbegin{ Call to SetForegroundWindow is required by API }SetForegroundWindow(IconMgr.HWindow);{ Popup local menu at the cursor position. }GetCursorPos(Pt);TheIcon.FPopupMenu.Popup(Pt.X, Pt.Y);{ Message post required by API to force task switch }PostMessage(IconMgr.HWindow, WM_USER, 0, 0);end;end;end;endelse{ If it isn’t a tray callback message, then call DefWindowProc }Result := DefWindowProc(FHWindow, Msg, wParam, lParam);end;end;{ TTrayNotifyIcon }constructor TTrayNotifyIcon.Create(AOwner: TComponent);begininherited Create(AOwner);FIcon := TIcon.Create;FTimer := TTimer.Create(Self);with FTimer dobeginEnabled := False;Interval := GetDoubleClickTime;OnTimer := OnButtonTimer;end;{ Keep default windows icon handy... }LoadDefaultIcon;end;destructor TTrayNotifyIcon.Destroy;beginif FIconVisible then SetIconVisible(False); // destroy iconFIcon.Free; // free stuffFTimer.Free;inherited Destroy;end;function TTrayNotifyIcon.ActiveIconHandle: THandle;{ Returns handle of active icon }begin{ If no icon is loaded, then return default icon }if (FIcon.Handle <> 0) thenResult := FIcon.HandleelseResult := FDefaultIcon;end;procedure TTrayNotifyIcon.LoadDefaultIcon;{ Loads default window icon to keep it handy. }{ This will allow the component to use the windows logo }{ icon as the default when no icon is selected in the }{ Icon property. }beginFDefaultIcon := LoadIcon(0, IDI_WINLOGO);end;procedure TTrayNotifyIcon.Loaded;{ Called after component is loaded from stream }begininherited Loaded;{ if icon is supposed to be visible, create it. }if FIconVisible thenSendTrayMessage(NIM_ADD, NIF_MESSAGE or NIF_ICON or NIF_TIP);end;procedure TTrayNotifyIcon.Notification(AComponent: TComponent;Operation: TOperation);begininherited Notification(AComponent, Operation);if (Operation = opRemove) and (AComponent = PopupMenu) thenPopupMenu := nil;end;procedure TTrayNotifyIcon.OnButtonTimer(Sender: TObject);{ Timer used to keep track of time between two clicks of a }{ double click. This delays the first click long enough to }{ ensure that a double click hasn’t occurred. The whole }{ point of these gymnastics is to allow the component to }{ receive onClicks and OnDblClicks independently. }begin{ Disable timer because we only want it to fire once. }FTimer.Enabled := False;{ if double click has not occurred, then fire single click. }if (not FNoShowClick) and Assigned(FonClick) thenFonClick(Self);FNoShowClick := False; // reset flagend;procedure TTrayNotifyIcon.SendTrayMessage(Msg: DWORD; Flags: UINT);{ This method wraps up the call to the API’s Shell_NotifyIcon }begin{ Fill up record with appropriate values }with Tnd dobegincbSize := SizeOf(Tnd);StrPLCopy(szTip, PChar(FHint), SizeOf(szTip));uFlags := Flags;uID := UINT(Self);Wnd := IconMgr.HWindow;uCallbackMessage := DDGM_TRAYICON;hIcon := ActiveIconHandle;end;Shell_NotifyIcon(Msg, @Tnd);end;procedure TTrayNotifyIcon.SetHideTask(Value: Boolean);{ Write method for HideTask property }const{ Flags to show application normally or hide it }ShowArray: array of integer = (sw_ShowNormal, sw_Hide);beginif FHideTask <> Value thenbeginFHideTask := Value;{ Don’t do anything in design mode }if not (csDesigning in ComponentState) thenShowWindow(Application.Handle, ShowArray);end;end;procedure TTrayNotifyIcon.SetHint(Value: string);{ Set method for Hint property }beginif FHint <> Value thenbeginFHint := Value;if FIconVisible then{ Change hint on icon on tray notification area }SendTrayMessage(NIM_MODIFY, NIF_TIP);end;end;procedure TTrayNotifyIcon.SetIcon(Value: TIcon);{ Write method for Icon property. }beginFIcon.Assign(Value); // set new icon{ Change icon on notification tray }if FIconVisible then SendTrayMessage(NIM_MODIFY, NIF_ICON);end;procedure TTrayNotifyIcon.SetIconVisible(Value: Boolean);{ Write method for IconVisible property }const{ Flags to add or delete a tray notification icon }MsgArray: array of DWORD = (NIM_DELETE, NIM_ADD);beginif FIconVisible <> Value thenbeginFIconVisible := Value;{ Set icon as appropriate }SendTrayMessage(MsgArray, NIF_MESSAGE or NIF_ICON or NIF_TIP);end;end;procedure TTrayNotifyIcon.SetPopupMenu(Value: TPopupMenu);{ Write method for PopupMenu property }beginFPopupMenu := Value;if Value <> nil then Value.FreeNotification(Self);end;const{ String to identify registered window message }TrayMsgStr = ’DDG.TrayNotifyIconMsg’;initialization{ Get a unique windows message ID for tray callback }DDGM_TRAYICON := RegisterWindowMessage(TrayMsgStr);IconMgr := TIconManager.Create;finalizationIconMgr.Free;end.==============================================================================25、关于窗体释放的问题(formX.free)?答:这个我知道,模式窗口用:form2 := TForm2.Create(Application);tryif form2.showModal = mrOK then{do Something}finallyform2.free;form2 := nil;end; 非模式窗口用:if not Assigned(form2) thenform2 := Tfrom2.Create(Application);form2.show;//然后在form2的Close事件中加入以下句Action := caFree;//在from2的Destory事件中加入以下句form2 := nil; 搞定!!!==============================================================================26、关于MDI窗体的问题?答:我不知道是如何实现,但我知道一个方法可以实现同样的功能,在打开子窗体前加一句button1.SendToBack; ==============================================================================27、小数点'.'的键号是什么?回车是#13,'.'是什么?答:你可以用此得出所有键的值procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);beginlabel1.caption:=IntToStr(key);end; =============================================================================listbox从文件中读取列表的操作ListBox1.Items.LoadFromFile(ExtractFilePath(Application.ExeName)+'aaa.txt');ListBox1.Items.Add(Edit1.Text); //添加了一个项目ListBox1.Items.SaveToFile(ExtractFilePath(Application.ExeName)+'aaa.txt');删除项目ListBox1.Items.Delete(listbox1.itemindex);------------------------------------判断窗体是否已经打开if frmPriceInput <> nil then ....注意:有时窗体虽然已经关闭,但没完全释放,最好在该窗体关闭的CLOSE事件里加入 frmPrintInput = nil;------------------------------------关闭MDI子窗口的方法在子窗口的OnClose事件处理过程中加入如下代码Action := caFree;Delphi为一个Form的关闭行为指定了四种方式,分别是:caNone -- 禁止Form被关闭caHide -- Form不被关闭,但是被隐藏。被隐藏的Form仍然可以被程序访问。caFree -- Form被关闭,并且释放其占用的资源。caMinimize -- Form被最小化而不是被关闭,这是MDI子窗口的默认关闭行为。------------------------------------系统配置文件 *.INI 的操作头部要引用IniFiles1、声明变量IniFile:TiniFile;2、指明路径IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'option.ini');3、读取变量,注意变量有类型之分readstring,readinteger...等titleBMPFile:=IniFile.ReadString('TitleImage','FileName',');//IniFile.ReadString('组名','变量','默认值')IniFile.ReadIntegerIniFile.ReadBool4、写入或修改变量IniFile.WriteString('标题','变量1','值');5、用完后释放IniFile.Free;------------------------------------动态读取图象Image1.Picture.LoadFromFile(titleBMPFile);------------------------------------fastreport自定义函数的用法1、先在普通工程窗体上定义好函数2、在frreport控件的userfunction中写入 if ansicomparetext( 'My_StrToRMB' , Name= 0 then val:=My_StrToRMB(frparser.Calc(p1));//MY_STRTORMB是函数名//如果定义多个函数,就多来几个IF即可。在报表设计视图中就可以调用这个函数了。------------------------------------数组是这样定义的sbh:array of string;------------------------------------treeview的用法//先定义项目序数和节点n: Integer;Node: TTreeNode;Node := Tree1.Selected;if (Node = nil) or (Node.StateIndex = -1) then Exit;//一般可以把不作反应的列的stateindex定为-1n := Node.StateIndex;------------------------------------Fields[] 通过索引返回字段,要自己選擇返回的類型!FieldByName()通过名字返回字段,要自己選擇返回的類型!FieldValues[]通过名字返回字段的值,自動化類型!------------------------------------调用外部程序方法用ShellExecute,在USES段加入SHELLAPI,使用时如: ShellExecute(handle,'open','c:\myapp\myapp.exe','-s',',SW_SHOWNORMAL); 第一个参数为父窗口句柄; 第二个参数为打开方式(OPEN,PRINT两种); 第三个参数为执行文件全路径; 第四个参数为执行文件参数; 第五个参数为执行文件开始运行时的初始目录; 第六个参数为为执行文件运行方式(SW_HIDE,SW_MAXIMIZE,SW_MINIMIZE,SW_RESTORE,SW_SHOW,SW_SHOWDEFAULT,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED,SW_SHOWMINNOACTIVE,SW_SHOWNA,SW_SHOWNOACTIVATE,SW_SHOWNORMAL);------------------------------------判断文件是否存在if not fileexists('db2.mdb.bak') then ...------------------------------------判断按键if Key=#13 then //如果回车则。。。------------------------------------退出关闭窗口 close;关闭程序:Application.Terminate;退出事件 exit;------------------------------------检测软件是否已在运行if GetLastError = ERROR_ALREADY_EXISTS then...------------------------------------定义函数是这样写的function IsReadOnly(b: Boolean; colors: Tcolor): Boolean;------------------------------------fastreport直接打印FrReport1.PrepareReport; //初始化FrReport1.PrintPreparedReport('1',1,True,frAll); //打印预览FrReport1.showreport;------------------------------------找开浏览器,进入某站点。(或调用WINDOWS程序)进入站点ShellExecute(Handle, PChar('OPEN'), PChar('http://www.devexpress.com/downloads/index.asp'),nil, nil, SW_SHOWMAXIMIZED);发送邮件ShellExecute(Handle, 'open', PChar('mailto:' + edtemail.Text + '?subject='), nil, nil, SW_SHOW);------------------------------------打开文件对话框if OpenPictureDialog.Execute then------------------------------------调用帮助文件Application.HelpFile := '..\..\Help\eBars.hlp';------------------------------------打开窗口TForm1.Create(self).ShowModal;------------------------------------取得当前执行程序的路径FPath := ExtractFilePath(Application.ExeName);或FileName := ExtractFilePath(ParamStr(0)) + '\MDB\电子通讯录.mdb';------------------------------------当前路径getcurrentdir------------------------------------判断当前鼠标处于某个位置(TAG) case TComponent(Sender).Tag of 0: begin ... lbBarBackgroud.Caption := sCustomImage; end; 1: begin ... lbBarBackgroud.Caption := sCustomImage; end; 2: begin ... lbBarBackgroud.Caption := sCustomImage; end;------------------------------------数据库连接1、建立一个adoconnection控件,命名为conn2、建立一个adodataset控件,命名为ds然后就可以用以下语句连接并执行SQL查询(本例是access的数据库,带密码)。conn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+getcurrentdir+'\data\pn.mdb;Persist Security Info=False;jet oledb:database password=80513';conn.Connected:=true;ds.Active:=false;ds.CommandText:='select 拜访日期,拜访时间,拜访客户,拜访地点,谈话内容 from khbf order by 拜访日期 desc';ds.Active:=true;------------------------------------ADODataSet1.State的用法if ADODataSet1.State in then ADODataSet1.Post ------------------------------------ADOQuery.open和ADOQuery.execSQL的区别用于存贮时如insert 只能用execSQL------------------------------------------------------------------------------------------------------------------------------------------------回车光标移到另一个输入框if key=#13 thencmb_name.SetFocus;------------------------------------播放声音playsound('c:\windows\media\start.wav',0,SND_ASYNC);------------------------------------列表框listbox增加项目cmb_name.Items.Add(adotable1.FieldValues['帐号']);------------------------------------listview用法ListView.Selected := ListView.Items;ListView.Selected.Focused := True;ListView.Selected.MakeVisible(False);ListView.Selected.IndexListView.Items.CountListView.Items.Delete(3) //删除第3个项目ListView.Items.Add.Caption:='dddddddd'; //增加一个项目ListView.Items.BeginUpdate;ListView.Items.EndUpdateListView.Canvas.Font.Color := clGrayText;if ListView.Selected <> nil then。。。。。//往listview添加项目先定义var itm: TListItem;然后listview.Items.Clear;itm := listview.Items.Add;itm.ImageIndex := 5;itm.Caption := Msg.Subject;itm.SubItems.Add('aaaaa');itm.SubItems.Add('ffffff');itm.SubItems.Add('ffdfdfdf');itm.SubItems.Add('oooo');------------------------------------静态调用DLL的方法有参数procedure CreateSms(Text: Pchar);stdcall;External 'SmsLib.dll';无参数procedure CreateSms;stdcall;External 'SmsLib.dll';------------------------------------确定、取消对话框作用if application.MessageBox('真的退出?','提示',mb_okcancel)=idok thenapplication.Terminate; //Terminate是终止程序showmessage('请先选中要修改的班级'); //这个是简单的显示提示框messagebox(self.Handle ,'价格输入不合法!','提示',MB_OK or MB_ICONASTERISK);------------------------------------调用窗体的步骤先引用该窗体的单元,然后建立窗体,最后显示出来。例1:use uxsgl;Application.CreateForm(TFmXsgl, FmXsgl);fmxsgl.ShowModal;例2:Frm_LendDetail:=TFrm_LendDetail.Create(self);Try Frm_LendDetail.ShowModal;Finally Frm_LendDetail.Free;End;------------------------------------数据库查询先建立数据源,然后添加一个TADOQUERYadoquery1.SQL.Clear adoquery1.Close;adoquery1.SQL.Add('select * from tkcb order by ckcb_kh');adoquery1.Open;aaa=adoquery1.FieldValues['ckcb_kc']; //取出当前记录某字段的值adoquery1.Next; //下一记录adoquery1.Close; //关闭查询------------------------------------判断键盘输入字符-chr(13)是回车 if key=chr(13) then bitbtn1.SetFocus;------------------------------------时间格式lblTime.Caption := FormatDateTime('yyyymmdd hh:nn:ss',Now);------------------------------------表数据的添加添加dmd是数据模块 tbl_zgdb是表名with dmd.tbl_zgdb do begin Append; FieldValues['HYZH'] := Edt_HYZH.text; FieldValues['XM'] := Edt_xm.text; FieldValues['XB'] := Edt_xb.text; FieldValues['dw'] := Edt_dw.text; FieldValues['ZZMM'] := zzmm; FieldValues['CSNY'] := trim(Edt_csny.text); FieldValues['GZSJ'] := Edt_gzsj.text; FieldValues['DBLB'] := dblb; FieldValues['ZCLB'] := zclb; FieldValues['XL'] := xl; FieldValues['BZ'] := Edt_bz.text; Post; close;end;------------------------------------列表框的选项值Edit1.Text:=listbox1.Items.Strings;------------------------------------Delphi键盘按键伪码用法:if key = chr(VK_RETURN) then...常数名称 十六进制值 十进制值 对应按键VK_LBUTTON 01 1 鼠标的左键VK_RBUTTON 02 2 鼠标的右键VK-CANCEL 03 3 Contol-break 执行VK_MBUTTON 04 4 鼠标的中键(三按键鼠标)VK_BACK 08 8 Backspace键VK_TAB 09 9 Tab键VK_CLEAR 0C 12 Clear键VK_RETURN 0D 13 Enter键VK_SHIFT 10 16 Shift键VK_CONTROL 11 17 Ctrl键VK_MENU 12 18 Alt键VK_PAUSE 13 19 Pause键VK_CAPITAL 14 20 Caps Lock键VK_ESCAPE 1B 27 Ese键VK_SPACE 20 32 Spacebar键VK_PRIOR 21 33 Page Up键VK_NEXT 22 34 Page Domw键VK_END 23 35 End键VK_HOME 24 36 Home键VK_LEFT 25 37 LEFT ARROW 键(←)VK_UP 26 38 UP ARROW键(↑)VK_RIGHT 27 39 RIGHT ARROW键(→)VK_DOWN 28 40 DOWN ARROW键(↓)VK_Select 29 41 Select键VK_EXECUTE 2B 43 EXECUTE键VK_SNAPSHOT 2C 44 Print Screen键 VK_Insert 2D 45 Ins键VK_Delete 2E 46 Del键VK_HELP 2F 47 Help键VK_0 30 48 0键VK_1 31 49 1键VK_2 32 50 2键VK_3 33 51 3键VK_4 34 52 4键VK_5 35 53 5键VK_6 36 54 6键VK_7 37 55 7键VK_8 38 56 8键VK_9 39 57 9键VK_A 41 65 A键VK_B 42 66 B键VK_C 43 67 C键VK_D 44 68 D键VK_E 45 69 E键VK_F 46 70 F键VK_G 47 71 G键VK_H 48 72 H键VK_I 49 73 I键VK_J 4A 74 J键VK_K 4B 75 K键VK_L 4C 76 L键VK_M 4D 77 M键VK_N 4E 78 N键VK_O 4F 79 O键VK_P 50 80 P键VK_Q 51 81 Q键VK_R 52 82 R键VK_S 53 83 S键VK_T 54 84 T键VK_U 55 85 U键VK_V 56 86 V键VK_W 57 87 W键VK_X 58 88 X键VK_Y 59 89 Y键VK_BZ 5A 90 Z键VK_NUMPAD0 60 96 数字键0键VK_NUMPAD1 61 97 数字键1键VK_NUMPAD2 62 98 数字键2键VK_NUMPAD3 63 99 数字键3键VK_NUMPAD4 64 100 数字键4键VK_NUMPAD5 65 101 数字键5键VK_NUMPAD6 66 102 数字键6键VK_NUMPAD7 67 103 数字键7键VK_NUMPAD8 68 104 数字键8键VK_NUMPAD9 69 105 数字键9键VK_MULTIPLY 6A 106 *键VK_ADD 6B 107 +键VK_SEPARATOR 6C 108 Separator键VK_SUBTRACT 6D 109 -键VK_DECIMAL 6E 110 .键VK_DIVIDE 6F 111 键VK_F1 70 112 F1键VK_F2 71 113 F2键VK_F3 72 114 F3键VK_F4 73 115 F4键VK_F5 74 116 F5键VK_F6 75 117 F6键VK_F7 76 118 F7键VK_F8 77 119 F8键VK_F9 78 120 F9键VK_F10 79 121 F10键VK_F11 7A 122 F11键VK_F12 7B 123 F12键VK_NUMLOCK 90 144 Num Lock 键VK_SCROLL 91 145 Scroll Lock键==================Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里的函数,使用前要先 Uses Math。 trunc 和 round 是 system unit 里的函数,缺省就可以用。 floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123 trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123 ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124 round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124==================================================如何把RGB颜色转变成Delphi的 Tcolor?form1.color:=rgbtocolor(255,0,0); 函数: --------- function RGBToColor(R,G,B:Byte): TColor; begin Result:=B Shl 16 or G Shl 8or R; end; =========================== //////////////////////////////////////////////////////////////////////////////// 回调函数(Callback Routine)的解释 MyWindowClassInfo = packed record Style:UINT ... lpFnWndProc:Pointer ... end; 应用程序只需要将一个能处理消息的函数地址指定给MyWindowClassInfo中的lpFnWndProc字段,执行环境就知道消息需要调用的函数,于是应用程序可以把任何的函数地址指定给该字段以代表可以处理窗口消息的函数,这个函数是由执行环境来调用的,因此这种函数也被称为回调函数(Callback Routine)。 回调函数的机制:调用者在初始化一个对象的时候,将一些参数传递给对象,同时将一个调用者可以访问的函数地址传递给该对象,这个函数就是调用者和被调用者之间的一种通知约定,当约定的事件发生时,被调用者就会按照回调函数地址调用该函数。 ///////////////////////////////////////////////////////////////////////////////////////// Object Inspector(对象检视器) Properties页显示窗体中当前被选择部件的属性信息 Events页列出了当前部件可以响应的事件 (小窍门:Object Inspector一直可见,可将鼠标移到Object Inspector上,按动右键,以启动Object Inspector的弹出式菜单,将其设置为Stay On Top。) 部件的调整与对齐 如果要精确地表述部件的尺寸,可以在Object Inspector上,改变Left(表示部件左边缘到窗体左边框的象素点数)、Top(表示窗体上边框到部件上边缘的象素点数)、 Width(部件本身的宽度)、Height(部件本身的高度)等属性。 使四个按钮对齐。先将四个按钮选为一组:按住并向右下方拖动鼠标左键,在窗体上画出围绕四个按钮的矩形,释放左键后,被选中的按钮周边会出现暗灰色的边框。选用Edit|Align命令, 或选中4个按钮,出现灰色边框后,点右键,选择position,后面align…等,是不同方式的对齐,可以调整同样大小的尺寸。 锁定部件 选择主菜单上的Edit|Lock Controls选项 设置窗体的缺省按钮 按钮的Default属性从False改成True,即将它设为窗体的缺省按钮 OnClick事件,即按钮接收到左键单击时应用程序所作出的反应 ColorDialog1.Execute; 程序的第一句用Execute方法,使得ColorDialog运行它本身 Label(标签)一般放在对象的旁边,用来标记这些对象,当用户使用“Alt+关键字母”时,将自动选中它所指向的对象。方法是设置Label部件的FocusControl属性,在值段中,选用与它关联对象的对象名。 Edit、MaskEdit、Memo部件都是用作接收、显示用户输入文本的。ReadOnly在运行时间内控制对象是否可以进行Windows的操作,当此值为False时,该框内的文本就不能被复制到剪贴板上。MaxLength可以设置输入文本的长度限制。用PasswordChar属性可以按照显示隐蔽密码的方法显示用户输入文本。当一个字段被加上高亮度显示时,按键操作会将这一字段删除,替换成当前的键盘输入。这种设置为操作提供了方便,您不必每次先删除原来的文本;但也可能会导致误删文本。将AutoSelect属性设置成False,这种替代功能就被取消了。 它的EditMask属性为它提供了过滤文本的格式。点动这一属性的省略按钮,会弹出过滤编辑对话框 Memo是备注框,与以上对象不同的是,它可以接收多行文本输入。将ScrollBars设置成ssVertical,可以为它加上一个垂直的滚行条。Align属性调整该对象在窗口中的对齐情况,有alNone(无对齐指定)、alBottom(底部对齐)、alClient(全窗口显示)等可以选择;而Alignment属性则决定了文本在框中的对齐显示格式。Lines属性访问的文本被存储在一个TStrings对象中,按动它的省略按钮,可以通过对话框向它增加文本,也可以用程序对这一属性进行操作,以达到修改或增加备注文本的目的。 Combo Box(组合框) 显示可用磁盘驱动器 List Box(列表框) Windows打开文件操作时显示文件列表
页:
[1]