Delphi 技巧集合

一、系统

1、打开其它程序、文件:

     uses ShellAPI;

    ShellExecute(Application.Handle, nil, PChar(FilePath), nil, nil, SW_SHOWNORMAL);

2、浏览某文件或文件夹目录:

     uses ShellAPI;

    ShellExecute(Application.Handle, nil, PChar('explorer.exe'),PChar('/e, '+ '/select,' + FilePath), nil, SW_NORMAL);

 

二、其它

1、限制只能输入数字

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
    if not (key in ['0'..'9',#8,#13]) then
        key:=#0;
end;

2、N分钟前的时间

var
    pDate:TDate;
    NowTime:String;
begin
    pDate:=now();
    pDate:=pDate-10/24/60;   //10分钟前时间
    NowTime:=FormatDateTime('yyyy-mm-dd hh:mm:ss',pDate);
end;

 3、StringGrid右击选中表格

procedure TFGLGL.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
    MousePos:   TSmallPoint;
begin
    if   Button   =   mbRight   then
    begin
        MousePos.x   :=   x;
        MousePos.y   :=   y;
        SendMessage(StringGrid1.Handle, WM_LBUTTONDOWN, 0, MAKELONG(x, y));
        SendMessage(StringGrid1.Handle, WM_LBUTTONUP, 0, MAKELONG(x, y));
    end;
end;

 

 

你可能感兴趣的:(Delphi)