cyberfan's blog

正其谊不谋其利,明其道不计其功

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  15 随笔 :: 489 文章 :: 44 评论 :: 0 Trackbacks
1、计算字符串中中文的字数
function TotalChineseCount(ans: AnsiString): Integer;
var
 wis: WideString;
begin
 wis := WideString( ans );
 Result := Length( ans ) - Length( wis );
end;

2、模拟按按下键盘键(如输入法中的软键盘)

//模拟在Edit组件中按下字母a键
PostMessage(Edit1.Handle,WM_KEYDOWN,65,0);
//模拟在窗体Form1中按下Tab键
PostMessage(Form1.Handle,WM_KEYDOWN,VK_TAB,0);

3、屏蔽系统功能键,如Ctrl+Alt+Del、Ctrl+Esc
var tempint:integer;
  SystemParametersinfo(SPI_SCREENSAVERRUNNING,1,@tempint,0);//屏蔽
  SystemParametersinfo(SPI_SCREENSAVERRUNNING,0,@tempint,0);//取消屏蔽

4、产生GUID
Uses ComObj, ActiveX, Windows;

function GetGUID:string;
var
 Id: TGUID;
begin
 if CoCreateGuid(Id) = S_OK then
  Result := GUIDToString(id);
end;

5、在ListBox移动鼠标时选择项目
procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
 i: integer;
begin
 i := y div listbox1.ItemHeight;
 if (listbox1.TopIndex + i) < listbox1.items.count then
 begin
  listbox1.ItemIndex := listbox1.TopIndex + i;
  caption := listbox1.Items[listbox1.ItemIndex];
 end;
end;

6、查找并选择指定的组合框列表内容

function TForm1.FindComboBoxList(Cbb: TComboBox; Const Text: String): Boolean;
var
 j: integer;
begin
 Result:=False;
 j:=cbb.Items.IndexOf(Text);
 if j>=0 then
 begin
  cbb.ItemIndex:=j;
  Result:=true;
 end;
end;

7、在TDbGrid选择全部记录
{-----------------------在TDbGrid选择全部记录-----------------------}
Function GridSelectAll(Grid: TDBGrid): Longint;
begin
 Result := 0;
 Grid.SelectedRows.Clear;
 with Grid.Datasource.DataSet do
 begin
  First;
  DisableControls;
  try
   while not EOF do
   begin
    Grid.SelectedRows.CurrentRowSelected := True;
    inc(Result);
    Next;
   end;
  finally
   EnableControls;
  end;
 end;
end;

8、窗口是否在最上面
procedure StayOnTop(Handle: HWND; OnTop: Boolean);
const
 csOnTop: array[Boolean] of HWND = (HWND_NOTOPMOST, HWND_TOPMOST);
begin
 SetWindowPos(Handle, csOnTop[OnTop], 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;

9、MEMO的自动卷屏
Delphi的MEMO控件的方法不带自动卷屏,所以只能是用Message。

卷屏到光标处: 

  SendMessage(DBMemo1.Handle, EM_SCROLLCARET, 0, 0);

向下卷屏一行

  SendMessage(RichEdit1.Handle, EM_SCROLL, SB_LINEDOWN, 0)
posted on 2005-08-12 16:01 cyberfan 阅读(297) 评论(0)  编辑 收藏 引用 所属分类: delphi
只有注册用户登录后才能发表评论。