📄 mylib.pas
字号:
unit mylib;
interface
uses
Windows, Messages, SysUtils, ADODB, Dialogs, StdCtrls, ComCtrls, ExtCtrls,
DBCtrls, Forms, Mask, DBGridEh;
procedure MsgError(s: string); //显示信息,有一个OK按钮,和一个ICONERROR
procedure OPENAdoQ(ADOqry1: TADOQuery; sqltxt: string);
procedure open1AdoQuery(ADOqry1: TADOQuery; fd1, tbl: string);
procedure open2AdoQuery(ADOqry1: TADOQuery; fd1, tbl: string);
procedure open3AdoQuery(ADOqry1: TADOQuery; fd1, tbl: string);
procedure ExecAdoQuery(ADOqry1: TADOQuery; sqltxt: string);
procedure addlistbox(ADOqry1: TADOQuery; fd1, tbl: string; listbox: TListBox);
procedure addcombox(ADOqry1: TADOQuery; fd1, tbl: string; combox: TComboBox);
procedure addcombox1(ADOqry1: TADOQuery; fd1,fd2, tbl,sqltxt: string; combox: TComboBox);
procedure addcombox2(ADOqry1: TADOQuery; fd1, tbl,sqltxt: string; combox: TComboBox);
procedure addcombox3(ADOqry1: TADOQuery; fd1, tbl: string; combox: TComboBox);
function ComboBoxIsEmpty(combox1: TComboBox; errmsg: string): boolean;
function EditIsEmpty(ed1: TEdit; errmsg: string): boolean;
function maskIsEmpty(ed1: TMaskedit; errmsg: string): boolean;
function editisNUM(ed1: TEdit; errmsg: string): boolean;
function editisNUM2(com:TComboBox; errmsg: string): boolean;
function editisNUM1(ed1: TEdit; errmsg: string): boolean;
Function GetCode(Splitter:char;Text:string):string;
procedure DelMsgADOQuery(handle: thandle; ADOqry1: TADOQuery);
procedure ehTitClick(Column: TColumnEh); {单击表格列头排序eh}
implementation
//=======================================================================
procedure MsgError(s: string); //显示信息,有一个OK按钮,和一个ICONERROR
begin
Application.MessageBox(pchar(s), '提示', MB_ICONWARNING);
end;
//====================================================================
procedure DelMsgADOQuery(handle: thandle; ADOqry1: TADOQuery);
var
sMsgCaption, sMsgText: string;
iMsgType, iUserResp: Integer;
begin
sMsgCaption := '警告!';
sMsgText := '你真的要删除选中资料吗?';
iMsgType := mb_okcancel + MB_ICONWARNING + MB_DEFBUTTON2;
iUserResp := MessageBox(handle, '你真的要删除选中资料吗?', '警告!',
mb_okcancel + MB_ICONWARNING + MB_DEFBUTTON2);
case iUserResp of
idok:
begin
ADOqry1.Delete;
end;
IDCANCEL:
begin
end;
end;
end;
//============================================================
procedure open1AdoQuery(ADOqry1: TADOQuery; fd1, tbl: string);
var s: string;
begin
s := 'select ' + fd1 + ' from ' + tbl + ' group by ' + fd1 + ' order by ' +
fd1;
with ADOqry1 do
begin
close;
sql.Clear;
sql.Add(s);
Open;
end;
end;
//======================================================================
procedure open2AdoQuery(ADOqry1: TADOQuery; fd1, tbl: string);
var s: string;
begin
s := 'select ' + fd1 + ' from ' + tbl;
with ADOqry1 do
begin
close;
sql.Clear;
sql.Add(s);
Open;
end;
end;
//======================= =========
procedure open3AdoQuery(ADOqry1: TADOQuery; fd1, tbl: string);
var s: string;
begin
s := 'select distinct ' + fd1 + ' from ' + tbl;
with ADOqry1 do
begin
close;
sql.Clear;
sql.Add(s);
Open;
end;
end;
//========================================================================
procedure ExecAdoQuery(ADOqry1: TADOQuery; sqltxt: string);
begin
with ADOqry1 do
begin
close;
sql.Clear;
sql.Add(sqltxt);
ExecSQL;
end;
end;
//======================================================================
procedure OPENAdoQ(ADOqry1: TADOQuery; sqltxt: string);
begin
with ADOqry1 do
begin
close;
sql.Clear;
sql.Add(sqltxt);
Open;
end;
end;
//========================================================================
procedure addlistbox(ADOqry1: TADOQuery; fd1, tbl: string; listbox: TListBox);
var
i, j: Integer;
begin
listbox.Clear;
open1AdoQuery(ADOqry1, fd1, tbl);
j := ADOqry1.RecordCount;
if j > 0 then
begin
for i := 1 to j do
begin
listbox.Items.Add(ADOqry1.FieldValues[fd1]);
ADOqry1.next;
end;
end;
end;
//========================================================================
procedure addcombox(ADOqry1: TADOQuery; fd1, tbl: string; combox: TComboBox);
var
i, j: Integer;
begin
combox.Clear;
open2AdoQuery(ADOqry1, fd1, tbl);
j := ADOqry1.RecordCount;
if j > 0 then
begin
for i := 1 to j do
begin
combox.Items.Add(ADOqry1.FieldValues[fd1]);
ADOqry1.next;
end;
end;
end;
//==================================================================
procedure addcombox3(ADOqry1: TADOQuery; fd1, tbl: string; combox: TComboBox);
var
i, j: Integer;
begin
combox.Clear;
open3AdoQuery(ADOqry1, fd1, tbl);
j := ADOqry1.RecordCount;
if j > 0 then
begin
for i := 1 to j do
begin
combox.Items.Add(ADOqry1.FieldValues[fd1]);
ADOqry1.next;
end;
end;
end;
//=======================================================================
procedure addcombox1(ADOqry1: TADOQuery; fd1,fd2, tbl,sqltxt: string; combox: TComboBox);
var
i, j: Integer;
begin
combox.Clear;
OPENAdoQ(ADOqry1, sqltxt);
j := ADOqry1.RecordCount;
if j > 0 then
begin
for i := 1 to j do
begin
combox.Items.Add(ADOqry1.FieldValues[fd1]+' >'+ADOqry1.FieldValues[fd2]);
ADOqry1.next;
end;
end;
end;
//=======================================================================
procedure addcombox2(ADOqry1: TADOQuery; fd1, tbl,sqltxt: string; combox: TComboBox);
var
i, j: Integer;
begin
combox.Clear;
OPENAdoQ(ADOqry1, sqltxt);
j := ADOqry1.RecordCount;
if j > 0 then
begin
for i := 1 to j do
begin
combox.Items.Add(ADOqry1.FieldValues[fd1]);
ADOqry1.next;
end;
end;
end;
//=======================================================================
function ComboBoxIsEmpty(combox1: TComboBox; errmsg: string): boolean;
begin
result := TRUE;
if trim(combox1.Text) = '' then
begin
MessageDlg(errmsg, mtWarning, [mbOk], 0);
combox1.SetFocus;
result := false;
end;
end;
//======================================================================
function EditIsEmpty(ed1: TEdit; errmsg: string): boolean;
begin
result := TRUE;
if trim(ed1.Text) = '' then
begin
MessageDlg(errmsg, mtWarning, [mbOk], 0);
ed1.SetFocus;
result := false;
end;
end;
//====================================================================
function maskIsEmpty(ed1: TMaskedit; errmsg: string): boolean;
begin
result := TRUE;
if trim(ed1.Text) = '' then
begin
MessageDlg(errmsg, mtWarning, [mbOk], 0);
ed1.SetFocus;
result := false;
end;
end;
//====================================================================
function editisNUM(ed1: TEdit; errmsg: string): boolean;
var
i: Integer;
begin
result := TRUE;
for i := 1 to length(ed1.Text) do
if not (ed1.Text[i] in ['0'..'9', #46]) then
begin
MessageDlg(errmsg, mtWarning, [mbOk], 0);
ed1.SetFocus;
result := false;
exit;
end;
end;
//==================================================================
function editisNUM2(com:TComboBox; errmsg: string): boolean;
var
i: Integer;
begin
result := TRUE;
for i := 1 to length(com.text) do
if not (com.Text[i] in ['0'..'9', #46]) then
begin
MessageDlg(errmsg, mtWarning, [mbOk], 0);
com.Clear;
com.SetFocus;
result := false;
exit;
end;
end;
//====================================================================
function editisNUM1(ed1: TEdit; errmsg: string): boolean;
var
i: Integer;
begin
result := TRUE;
for i := 1 to length(ed1.Text) do
if not (ed1.Text[i] in ['0'..'9']) then
begin
MessageDlg(errmsg, mtWarning, [mbOk], 0);
ed1.SetFocus;
result := false;
exit;
end;
end;
procedure ehTitClick(Column: TColumnEh); {单击表格列头排序eh}
begin
if Column.FieldName <> '' then
begin
if Column.Title.SortMarker = smDownEh then
begin
Column.Title.SortMarker := smupEh;
(Column.Grid.DataSource.DataSet as TADOQuery).Sort :=
Column.FieldName + ' DESC';
end
else
begin
Column.Title.SortMarker := smDownEh;
(Column.Grid.DataSource.DataSet as TADOQuery).Sort :=
Column.FieldName + ' ASC';
end;
end;
end;
//============================================================================
Function GetCode(Splitter:char;Text:string):string;
var
BeginPos,EndLen:integer;
begin
Text:=Trim(Text);
BeginPos:=Pos(Splitter,Text)+1;
EndLen:=Length(Text)-Pos(Splitter,Text);
Result:=Copy(Text,BeginPos,EndLen);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -