1、怎么樣在delphi中調(diào)動(dòng)其它*.exe文件? 例如:winexec(''d:\Project1.exe'',sw_show); ============================================================================== 2、如何讓工程運(yùn)行時(shí)主窗體就是最大化的? 答:設(shè)置主窗體的WindowsState屬性為wsMaximized就可以了! wsNormal 窗體以普通狀態(tài)顯示 wsMinimized 窗體以最小化狀態(tài)顯示。 wsMaximized 窗體以最大化狀態(tài)顯示。 ============================================================================== 3、我想先->閃現(xiàn)窗體->主窗體->登錄窗體,工程源文件怎么設(shè)置? 答: ⒈開始一個(gè)新工程。給表格起名為MainForm,MainForm的單元起名為Main, 工程文 件起名為Test。 ⒉在MainForm中插入一個(gè)Button部件,將其Caption屬性設(shè)為“關(guān)閉”,為該部件 的onClick事件創(chuàng)建一個(gè)過(guò)程,并在過(guò)程的begin和end之間插入Close語(yǔ)句。 ⒊在應(yīng)用程序添加一個(gè)表格,將這個(gè)表格起名為MoveForm,MoveForm 的單元起名 為Move。 ⒋為便于演示,在MoveForm中插入一個(gè)Label部件,設(shè)置其Caption 屬性為“歡迎 進(jìn)入本系統(tǒng)”。 5.下一步修改工程的源代碼。選擇View/Project Source,修改begin和end之間的 語(yǔ)句如下: 程序清單Test.Dpr program Test uses forms, Main in ''MAIN.PAS'', Move in ''Move.PAS'' {$R *.RES} begin MoveForm:=TMoveForm.Create(Application); MoveForm.Show; MoveForm.Update; Application.CreateForm(TMainForm,MainForm); MoveForm.Hide; MoveForm.Free; Application.Run; end. 第一條語(yǔ)句創(chuàng)建了對(duì)象,該對(duì)象存在內(nèi)存中,但還不能看見(jiàn), 為了讓它出現(xiàn)并更 新它的內(nèi)容,調(diào)用對(duì)象的Show和Update成員函數(shù):Show和Update。 當(dāng)閃現(xiàn)窗口使 用完后,用Hide函數(shù)將它隱藏起來(lái),然后用Free函數(shù)釋放它所占據(jù)的內(nèi)存。 6.如果此刻你編譯和運(yùn)行程序,MoveForm窗口一閃而過(guò), 你可能未來(lái)得及看 清。為使MoveForm窗口顯示幾秒種,我們可為MainForm的OnCreate 事件創(chuàng)建一個(gè) 處理程序,延遲MoveForm窗口的顯現(xiàn)時(shí)間。 program TMainForm.FormCreate(sender:Tobject); var currentTime:LongInt; begin currentTime:=GetTickCount div 1000; while ((GetTickCount div 1000)<(currentTime+3) do {不做任何事); end; end. GetTickCount函數(shù)返回窗口啟動(dòng)后過(guò)去的毫秒數(shù),這個(gè)值除以1000 轉(zhuǎn)化為秒數(shù)。 此時(shí)你編譯運(yùn)行程序,就能得到一個(gè)延遲3秒多的閃現(xiàn)窗口。 為閃現(xiàn)窗口添加上Image部件,再對(duì)字體及窗口進(jìn)行修飾,我們就能為應(yīng)用程 序,創(chuàng)建一個(gè)精美的封面或在程序啟動(dòng)時(shí)顯示重要提示。 制作登錄窗體一個(gè)很方便的方法就是主窗體作為主窗體,登錄成功Hide掉就行了。 如果登錄窗體不可以作為主窗體,那么和閃現(xiàn)窗體一樣的方法創(chuàng)建登錄窗體,加在Application.Run;之前,MoveForm.Free;之后, 用showmodal顯示登錄窗體 ============================================================================== 4、button上面的文字怎么樣換行? 答: button控件不行 bitbtn控件可以。 bitbtn1.caption:=''aaaa''#13''bbbbb'' ============================================================================== 5、怎么樣判別焦點(diǎn)是否在某個(gè)控件上? 答: if Tobject.focused then //焦點(diǎn)在某某控件上 else ============================================================================== 6、怎么樣在程序中使一個(gè)節(jié)點(diǎn)的子節(jié)點(diǎn)展開及收閉? 答: treeview1.selected.Expanded; //判斷節(jié)點(diǎn)的子節(jié)點(diǎn)是否展開True展開,否則閉攏 treeview1.selected.Expand(True);//子節(jié)點(diǎn)展開 treeview1.selected.collapse(True)://子節(jié)點(diǎn)閉攏 樹節(jié)點(diǎn)全部展開: procedure TForm1.Button1Click(Sender: TObject); var node:TTreeNode; begin if treeview1.Items[0]<>nil then begin node:=treeview1.Items[0]; node.Expand(true); while node.getNextSibling<>nil do begin node:=node.getNextSibling; node.Expand(true); end; end; end; 樹節(jié)點(diǎn)全部收縮: procedure TForm1.Button2Click(Sender: TObject); var node:TTreeNode; begin if treeview1.Items[0]<>nil then begin node:=treeview1.Items[0]; node.Collapse(true); while node.getNextSibling<>nil do begin node:=node.getNextSibling; node.Collapse(true); end; end; end; ============================================================================== 7、如何用delphi編程實(shí)現(xiàn)給access數(shù)據(jù)庫(kù)加密碼? 答:1,新建Project。 2,在FORM中放入ADOConnection控件。 3,雙擊ADOConnection控件,然后點(diǎn)擊Build...按鈕,在“提供者”頁(yè)中選擇“Microsoft Jet 4.0 OLE DB Provider”,然后點(diǎn)擊“下一步”按鈕,在“連接”頁(yè)中選擇要連接的Access數(shù)據(jù)庫(kù)的路徑和數(shù)據(jù)庫(kù)的文件名,這時(shí)如果點(diǎn)“測(cè)試連接”按鈕 時(shí),出現(xiàn)“初始化提供者時(shí)發(fā)生錯(cuò)誤,測(cè)試連接失敗,密碼無(wú)效”的錯(cuò)誤提示。 4,這時(shí)點(diǎn)“所有”頁(yè),然后雙擊“Jet OLEDB:Database Password”,出現(xiàn)對(duì)話框,添入密碼后,選擇“連接”頁(yè)中的“測(cè)試連接”按鈕,出現(xiàn)“測(cè)試連接成功”的對(duì)話框。把ADOConnection控件的 LoginPromtp設(shè)為false. 5,設(shè)置連接完成。 ============================================================================== 8、如何判斷Treeview中我選中的節(jié)點(diǎn)是否有子節(jié)點(diǎn)?如果沒(méi)有給出提示啊? 答: if Treeview.Selected.HasChildren then //有 else //無(wú) var Node :TTreeNode; begin Node :=TreeView1.Selected; if Node.HasChildren then .... 對(duì)復(fù)雜的程序最好用Node過(guò)渡 ============================================================================== 9、能否解釋一下try...except...end及try...finally...end;? 1.(1)是用于撲捉異常,(2)是用于保證代碼執(zhí)行的完整性 2.(1)中finally處的代碼不管什么情況都會(huì)被執(zhí)行,(2)中except處的代碼僅在發(fā)生異常時(shí)才會(huì)執(zhí)行 3.try finally之間的代碼雖可保證finally 和 end之間的程序能執(zhí)行,但不能保證程序不崩潰, 而try except就不會(huì)使程序崩潰 ============================================================================== 10、怎么樣在主程序控制器中加入音樂(lè)? 在implementation下加入 mmsystem單元(windows多媒體函數(shù)動(dòng)態(tài)聯(lián)結(jié)庫(kù))。然後在的onShow,onCreate事件中編寫代碼:sndplaysound(''sound.wav'',snd_async) ============================================================================== 11、我在form1上有四個(gè)edit,輸完后我想用下上箭頭鍵進(jìn)行上移下移?怎么辦? 答: procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=vk_down then perform(WM_NEXTDLGCTL,0,0) else if key=vk_up then perform(WM_NEXTDLGCTL,1,0); end; ============================================================================== 12、如何用delphi5實(shí)現(xiàn)讀文本文件指定的一行,并得到文本文件的總行數(shù)?謝謝! 答: Delphi讀文件文件一般使用Readln過(guò)程,如要讀第3行可以這樣: var i : Integer; F: TextFile; S: string; begin if OpenDialog1.Execute then { Display Open dialog box } begin AssignFile(F, OpenDialog1.FileName); { File selected in dialog } Reset(F); For i = 1 To 3 Do Readln(F, S); Edit1.Text := S; { Put string in a TEdit control } CloseFile(F); . end; 要統(tǒng)計(jì)總行數(shù),只能從頭逐行讀,直到文件尾(Eof函數(shù)為True),每讀一行計(jì)數(shù)器加1。 不過(guò)由于文本文件的每行長(zhǎng)度不相等,它不能象數(shù)據(jù)庫(kù)文件那樣想讀那行就讀哪行,只能順序讀。 上面的方法容易理解,也容易實(shí)現(xiàn)。如果希望提高速度,編程上要麻煩一些,可以以二進(jìn)制方式打開文件,將所有內(nèi)容讀入一個(gè)內(nèi)存變量,然后使用Pos函數(shù)查找其中的回車(#13)個(gè)數(shù),這樣可以快速地統(tǒng)計(jì)總行數(shù)并能快速地找到指定行。 ============================================================================== 13、制作主窗口顯示前的版權(quán)窗口 答: 在 工程文件中選File->New Form新建一個(gè)窗口,設(shè)計(jì)好窗口的外觀。給窗口起名為AboutBox,選Project->Options,將新建的窗口從自動(dòng)建立中去掉。 選View->Project Source,打開工程文件的源文件,在下面加入紅色的句子。 Uses AboutBox Var lTime :TDateTime; Begin Application.Initialize(); AboutBox=TAboutBox.Create(AboutBox); AboutBox.Show; AboutBox.Update; lTime=GetTickCount; Application.CreateForm(TMainForm,MainForm); while((GetTickCount-lTime) / 1000 <3) do; AboutBox.Hide; AboutBox.Free; Application.Run; end; ============================================================================== 14、Delphi中RichEdit的奧妙 一、如何得知當(dāng)前行號(hào) 用RichEdit(或者memo)控件制作文本編輯器時(shí),通過(guò)訪問(wèn)lines?count屬性可以得到總行數(shù),但是若想知道光標(biāo)當(dāng)前所在行的行號(hào)就麻煩了,因?yàn)閐elphi沒(méi)有提供這個(gè)屬性。要實(shí)現(xiàn)這個(gè)編輯器必備功能,就須調(diào)用em_ LineFromChar。 請(qǐng)?jiān)囋囅旅娴某绦颉? 先在窗口中布置一個(gè)RichEdit或者memo(命名為editor),以及一個(gè)button。在button的onclick事件中寫入下列代碼。 var CurrentLine:Integer; begin CurrentLine:=Editor.Perform(em_ LineFromChar,SFFFF,0); Application.MessageBox(PChar(′當(dāng)前行號(hào)是′+I(xiàn)ntToStr(CurrentLine)),′消息′,mb_ iconinformation); end; 需要注意的是,第一行的行號(hào)為零。 二、如何撤消操作(undo) 對(duì)于memo來(lái)說(shuō),實(shí)現(xiàn)undo是不需編程的,只要讓popupmenu屬性為空,運(yùn)行時(shí)就能用鼠標(biāo)右鍵激活一個(gè)常用操作菜單,其中包括撤消、剪切、復(fù) 制、粘貼、刪除和全選六項(xiàng)。 但可惜的是,這一招對(duì)于功能強(qiáng)大的RichEdit控件居然行不通,害得我們還要自己設(shè)計(jì)一個(gè)popupmemu。當(dāng)你用 CutToClipBoard等語(yǔ)句輕松而順利地完成了“剪切”等功能,接著便會(huì)無(wú)奈地發(fā)現(xiàn),竟找不到undo或cancel之類的語(yǔ)句來(lái)執(zhí)行“撤消”。 這時(shí)你需要這樣處理: RichEdit1?Perform(EM_UNDO,0,0); 另外還應(yīng)檢查是否允許撤消,從而開啟或關(guān)閉彈出菜單中的“撤消”項(xiàng): Undo1?Enabled:=RichEdit? Perform(EM_CANUNDO,0,0)<>0; 以上程序在Delphi3中調(diào)試通過(guò)?! ? ============================================================================== 15、在主窗口中打開另一個(gè)獨(dú)立的窗口,而這個(gè)被打開的窗口固定顯示在..? 答: procedure TForm2.FormCreate(Sender: TObject); begin form2.Hide; self.Parent:=form1.Panel1; end; ============================================================================== 16、SaveDialog1確認(rèn)文件存不存在的辦法? 答: procedure TForm1.SaveDialog1CanClose(Sender: TObject; var CanClose: Boolean); begin if FileExists(SaveDialog1.FileName) then //如果文件已經(jīng)存在 if MessageDlg(''文件已經(jīng)存在,保存嗎?'', mtConfirmation, [mbYes, mbNo], 0) <> mrYes then Button2.Click ; //如果選擇了覆蓋,則退出,否則,重新讓用戶選擇文件 end; ============================================================================== 17、正確關(guān)閉一個(gè)MDI子窗口? 答: Delphi中MDI子窗口的關(guān)閉方式默認(rèn)為縮小而不是關(guān)閉,所以當(dāng)你單擊子窗口右上角的關(guān)閉按鈕時(shí)會(huì)發(fā)覺(jué)該子窗口只是最小化,而不是你預(yù)期的那樣被關(guān)閉。解決辦法是在子窗口的OnClose事件處理過(guò)程中加入如下代碼,示例: procedure ChildForm.OnClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end; Delphi為一個(gè)Form的關(guān)閉行為指定了四種方式,分別是: caNone 禁止Form被關(guān)閉 caHide Form不被關(guān)閉,但是被隱藏。被隱藏的Form仍然可以被程序訪問(wèn)。 caFree Form被關(guān)閉,并且釋放其占用的資源。 caMinimize Form被最小化而不是被關(guān)閉,這是MDI子窗口的默認(rèn)關(guān)閉行為。 ============================================================================== 18、怎樣記MDI子窗口不在母體運(yùn)行時(shí)就被打開? 答: 在project下的options中forms里面除了form1外,其余的移到右邊的框里,然后在調(diào)用顯示的按鈕下編寫語(yǔ)句,以form2調(diào)用為例: form2:=Tform2.create(self); form2.show; ============================================================================== 19、限制FORM的大小 答: 在FORM私有聲明部分加上如下一行: procedure WMGetMinMaxInfo( var Message:TWMGetMinMaxInfo );message WM_GETMINMAXINFO; 在聲明部分加上如下幾行: procedure TForm1.WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo ); begin with Message.MinMaxInfo^ do begin ptMaxSize.X := 200; ptMaxSize.Y := 200; ptMaxPosition.X := 99; ptMaxPosition.Y := 99; end; Message.Result := 0; {告訴Windows你改變了 minmaxinfo} inherited; end; ============================================================================== 20、隨機(jī)數(shù)生成法 答: Randomize; rn:=inttostr(random(9999)); rn1:=inttostr(random(9999)); ..... ============================================================================== 21、怎樣把程序隱藏起來(lái),在WINDOWS界面上沒(méi)有顯示?? 答: 在application.run之前加入application.showmain:=false! ============================================================================== 22、怎樣將一個(gè)form1.free的form1窗體重新顯示? 答: form2:=TForm2.Create(application); form2.Show; 如果你要?jiǎng)?chuàng)建的Form2窗體能嵌入一個(gè)Panel中,指定Parent: form2:=TForm2.Create(application); form2.Parent:=panel1; form2.Show; ============================================================================== 23、我想在bitbtn上設(shè)快捷按鈕Esc,怎么辦? 答: procedure TForm1.BitBtn1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=27 then application.Terminate; end; 設(shè)它的cancel屬性為true就行了~~ ============================================================================== 24、什么叫做托盤區(qū)? 答: 托盤區(qū)就是在windows的狀態(tài)欄下方顯示時(shí)鐘、輸入法狀態(tài)的地方, 要把你的程序顯示在托盤區(qū): 下面是一個(gè)托盤類,只要把下面粘貼到文本文件中,改成TrayIcon.pas,使用時(shí)uses TrayIcon就可以了。 先聲明一個(gè)全局變量: var tray:TTrayNotifyIcon; 然后在窗體的OnCreate事件中: tray:=TTrayNotifyIcon.Create(self);//將窗體創(chuàng)建為托盤 tray.Icon:=application.Icon;//定義托盤的顯示圖標(biāo) tray.IconVisible:=true;//托盤可見(jiàn) tray.PopupMenu:=popmenu;//給托盤定義一個(gè)右擊時(shí)的彈出菜單 tray.OnDblClick:=trayDblClick;//給托盤定義一個(gè)雙擊事件(當(dāng)然要自己寫了,不過(guò)多數(shù)情況只有一行,就是Form1.show); unit TrayIcon; interface uses Windows, SysUtils, Messages, ShellAPI, Classes, Graphics, Forms, Menus, StdCtrls, ExtCtrls; type ENotifyIconError = class(Exception); TTrayNotifyIcon = class(TComponent) private FDefaultIcon: 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); protected procedure Loaded; override; procedure LoadDefaultIcon; virtual; procedure Notification(AComponent: TComponent; Operation: TOperation); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property 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 } type TIconManager = class private FHWindow: HWnd; procedure TrayWndProc(var Message: TMessage); public constructor Create; destructor Destroy; override; property HWindow: HWnd read FHWindow write FHWindow; end; var IconMgr: TIconManager; DDGM_TRAYICON: Cardinal; constructor TIconManager.Create; begin FHWindow := AllocateHWnd(TrayWndProc); end; destructor TIconManager.Destroy; begin if 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. } var Pt: TPoint; TheIcon: TTrayNotifyIcon; begin with Message do begin { if it’s the tray callback message } if (Msg = DDGM_TRAYICON) then begin TheIcon := 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: begin TheIcon.FNoShowClick := True; if Assigned(TheIcon.FOnDblClick) then TheIcon.FOnDblClick(Self); end; WM_RBUTTONDOWN: begin if Assigned(TheIcon.FPopupMenu) then begin { 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; end else { 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); begin inherited Create(AOwner); FIcon := TIcon.Create; FTimer := TTimer.Create(Self); with FTimer do begin Enabled := False; Interval := GetDoubleClickTime; OnTimer := OnButtonTimer; end; { Keep default windows icon handy... } LoadDefaultIcon; end; destructor TTrayNotifyIcon.Destroy; begin if FIconVisible then SetIconVisible(False); // destroy icon FIcon.Free; // free stuff FTimer.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) then Result := FIcon.Handle else Result := 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. } begin FDefaultIcon := LoadIcon(0, IDI_WINLOGO); end; procedure TTrayNotifyIcon.Loaded; { Called after component is loaded from stream } begin inherited Loaded; { if icon is supposed to be visible, create it. } if FIconVisible then SendTrayMessage(NIM_ADD, NIF_MESSAGE or NIF_ICON or NIF_TIP); end; procedure TTrayNotifyIcon.Notification(AComponent: TComponent; Operation: TOperation); begin inherited Notification(AComponent, Operation); if (Operation = opRemove) and (AComponent = PopupMenu) then PopupMenu := 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) then FonClick(Self); FNoShowClick := False; // reset flag end; 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 do begin cbSize := 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[Boolean] of integer = (sw_ShowNormal, sw_Hide); begin if FHideTask <> Value then begin FHideTask := Value; { Don’t do anything in design mode } if not (csDesigning in ComponentState) then ShowWindow(Application.Handle, ShowArray[FHideTask]); end; end; procedure TTrayNotifyIcon.SetHint(Value: string); { Set method for Hint property } begin if FHint <> Value then begin FHint := 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. } begin FIcon.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[Boolean] of DWORD = (NIM_Delete, NIM_ADD); begin if FIconVisible <> Value then begin FIconVisible := Value; { Set icon as appropriate } SendTrayMessage(MsgArray[Value], NIF_MESSAGE or NIF_ICON or NIF_TIP); end; end; procedure TTrayNotifyIcon.SetPopupMenu(Value: TPopupMenu); { Write method for PopupMenu property } begin FPopupMenu := 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; finalization IconMgr.Free; end. ============================================================================== 25、關(guān)于窗體釋放的問(wèn)題(formX.free)? 答: 這個(gè)我知道,模式窗口用:form2 := TForm2.Create(Application); try if form2.showModal = mrOK then {do Something} finally form2.free; form2 := nil; end; 非模式窗口用:if not Assigned(form2) then form2 := Tfrom2.Create(Application); form2.show; //然后在form2的Close事件中加入以下句 Action := caFree; //在from2的Destory事件中加入以下句 form2 := nil; 搞定!!! ============================================================================== 26、關(guān)于MDI窗體的問(wèn)題? 答: 我不知道是如何實(shí)現(xiàn),但我知道一個(gè)方法可以實(shí)現(xiàn)同樣的功能,在打開子窗體前加一句 button1.SendToBack; ============================================================================== 27、小數(shù)點(diǎn)''.''的鍵號(hào)是什么?回車是#13,''.''是什么? 答: 你可以用此得出所有鍵的值procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin label1.caption:=IntToStr(key); end; |
|