1. DLL的资源释放问题
EXITPROC
//*******************
//释放资源
//*******************
var
dllExit: Pointer;
procedure MyExit;
begin
//资源释放
ExitProc := dllExit;
end;
//******************************
//创建资源
//******************************
begin
// 资源创建
ExitProc := @MyExit;
dllExit := ExitProc;
end.
这种释放方式不能在动态载入下用,即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.
应该用单元里面加initialization和finalization来控制
2. DLL引用传入的Tquery组件应注意Close和UnPrepare,如下:
其中InitDriver是导出函数
Tquery
function 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;
变体记录使用能够容纳可变部分最大长度的空间来存储!而CASE不占存储,只是用来判别可变部分的类型。
CASE TAG:INTEGER OF..... VAR.TAG :=1;其实是没有效果的!
4.GRID 右键选中 并显示右键菜单
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); // 也可以用这个获取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; //修改选中区域
// 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.结构体指针的NEW和DISPONSE方法
暂缺
6.opendialog会影响系统当前工作目录,即不能用'.\file'而要用ExtractFileDir(Application.Exename)+'file';