DELPHI之备忘(二)
1. DLL的資源釋放問題
EXITPROC//*******************
//釋放資源
//*******************
var
??dllExit:?Pointer;
procedure?MyExit;
begin
//資源釋放
?ExitProc?:=?dllExit;
end;
//******************************
//創(chuàng)建資源
//******************************
begin
??//?資源創(chuàng)建
??ExitProc?:=?@MyExit;
??dllExit?:=?ExitProc;
end.
這種釋放方式不能在動(dòng)態(tài)載入下用,即loadLibrary方式載入,HELP幫助說明如下:
Do not use ExitProc in a dynamically loaded package. This procedure is called when the process halts, not when a package or DLL is unloaded. If you set ExitProc from a package or DLL, it may interfere with the ExitProc of the host executable. Because ExitProc is not compatible with packages, it is recommended that you add code to the finalization section of a unit instead. Inside a DLL, you can use the DLLProc variable instead.
應(yīng)該用單元里面加initialization和finalization來控制
2. DLL引用傳入的Tquery組件應(yīng)注意Close和UnPrepare,如下:
其中InitDriver是導(dǎo)出函數(shù)
Tqueryfunction?InitDriver(const??AOwner:TComponent;const?Aquery:Tquery):Byte;stdcall;
begin
??result?:=?1;
??if?fileexists('.\SQL\s.SQL')?then?begin
????aquery.Close;
????aquery.SQL.LoadFromFile('.\SQL\s.SQL');????
????//aquery.Prepare;不能用
????aquery.ParamByName('param').AsInteger?:=?1????;
????aquery.Open;
????while?not?aquery.Eof?do?begin
??????。。。。?
??????aquery.Next;
????end;
????aquery.Close;
????aquery.UnPrepare;?
??end;??
??result?:=?0;
end;
3. 變體記錄
變體記錄TMessage?=?packed?record
????Msg:?Cardinal;
????case?Integer?of
??????0:?(
????????WParam:?Longint;
????????LParam:?Longint;
????????Result:?Longint);
??????1:?(
????????WParamLo:?Word;
????????WParamHi:?Word;
????????LParamLo:?Word;
????????LParamHi:?Word;
????????ResultLo:?Word;
????????ResultHi:?Word);
end;
變體記錄使用能夠容納可變部分最大長度的空間來存儲(chǔ)!而CASE不占存儲(chǔ),只是用來判別可變部分的類型。
CASE TAG:INTEGER OF.....? VAR.TAG :=1;其實(shí)是沒有效果的!
4.GRID 右鍵選中 并顯示右鍵菜單
procedure?Tform.sgaddressMouseUp(Sender:?TObject;?Button:?TMouseButton;
??Shift:?TShiftState;?X,?Y:?Integer);
var????p:Tpoint;selectrow,selectcol?:integer;
????//???GrdCrd:???TGridCoord;
????myRect:?TGridRect;
begin
??if?button?=?mbRight?then?begin
???//?grdcrd?:=?sgaddress.MouseCoord(x,y);??//?也可以用這個(gè)獲取cell
????sgaddress.MouseToCell(x,y,selectcol,selectrow);
????if?selectcol?<?0?then?exit;
????if?selectrow?<?0?then?exit;
????myRect.Left?:=0;//?selectcol;
????myRect.Right?:=sgaddress.ColCount-1;?//selectcol;
????myRect.Top?:=?selectrow;
????myRect.Bottom?:=?selectrow;
????sgaddress.Selection?:=?myRect;??//修改選中區(qū)域
???//?if?(y?>=?sgaddress.CellRect(grdcrd.X,grdcrd.Y).Top)
???//??and?(y?<=?(sgaddress.CellRect(grdcrd.X,grdcrd.Y).Top+15))?then
????if?(y?>=?sgaddress.CellRect(selectcol,selectrow).Top)
?????and?(y?<=?(sgaddress.CellRect(selectcol,selectrow).Top+15))?then?begin
????GetCursorPos(P);
????PopupMemu.Popup(p.x,p.y);
????end;
??end;
end;
5.結(jié)構(gòu)體指針的NEW和DISPONSE方法?
暫缺
6.opendialog會(huì)影響系統(tǒng)當(dāng)前工作目錄,即不能用'.\file'而要用ExtractFileDir(Application.Exename)+'file';
轉(zhuǎn)載于:https://www.cnblogs.com/enli/archive/2008/12/17/1356744.html
總結(jié)
以上是生活随笔為你收集整理的DELPHI之备忘(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 软件架构设计原则--开闭原则
- 下一篇: c study_13