⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shareu.pas

📁 包含详细的代码设计,实现图书管理系统功能.是一个很好的实例
💻 PAS
字号:
unit ShareU;

interface
uses ADODB,DataModule,StdCtrls,SysUtils,StrUtils,Forms,Classes,ShellApi,
     Windows,Controls,Menus,ComCtrls;

procedure getOrder(ListB:TlistBox);
function CClearData(form:TForm):boolean;
procedure OpenForm(FormClass: TFormClass;var AForm;AOwner:TComponent=nil;modal:boolean=false);//打开窗体
function ShowAbout():boolean;
function GetOSInfo:string;      //系统信息程序
function GetMemoryInfo:integer; //可用资源程序
function CheckKey(var Key: char;str:string):boolean;
procedure CloseAllForm;
procedure DisabledMenu;//使所有菜单不可用
procedure EnabledMenu(menuname:string); //获得用户可操作的菜单
procedure draw(form:tform);             //绘制窗体边框

  var
    CurUser:string;               //当前用户名;
    CurState:boolean;             //true为当前已登陆,false为头次登陆
    CurUserLonginTime:tdatetime;  //储存登陆时间
    ExportExcelListView:String;   //导出EXCEL的控件名
implementation

uses MainU,LogU;


procedure draw(form:tform);
var
  dc : hDc;
  Pen : hPen;
  OldPen : hPen;
  OldBrush : hBrush;
begin
  dc := GetWindowDC(form.handle);
  //msg.Result := 1;
  Pen := CreatePen(PS_SOLID, 1, RGB(250, 55, 20));
  OldPen := SelectObject(dc, Pen);
  OldBrush := SelectObject(dc, GetStockObject(NULL_BRUSH));
  Rectangle(dc, 0,0, form.Width, form.Height);
  SelectObject(dc, OldBrush);
  SelectObject(dc, OldPen);
  DeleteObject(Pen);
  ReleaseDC(form.Handle, form.Canvas.Handle);
end;
procedure DisabledMenu;//使所有菜单不可用
var
  I:integer;
begin
    for i:=0 to mainf.ComponentCount-1 do
    begin
        if (mainf.Components[i] is TMenuItem) then
          (mainf.Components[i] as TMenuItem).Enabled:=false;
        if (mainf.Components[i] is TToolButton) then
          (mainf.Components[i] as TToolButton).Enabled:=false;
    end;
end;
procedure EnabledMenu(menuname:string);//获得用户可操作的菜单
begin
     if (Mainf.FindComponent(menuname)<>nil) then
     begin
       if (Mainf.FindComponent(menuname) is TMenuItem) then
         (Mainf.FindComponent(menuname) as TMenuItem).Enabled:=true;
       if (Mainf.FindComponent(leftstr(menuname,length(menuname)-4)+'TB') is TToolButton) then
         (Mainf.FindComponent(leftstr(menuname,length(menuname)-4)+'TB') as
                                                    TToolButton).Enabled:=true;
      end;
end;
procedure CloseAllForm;
var
  i:integer;
begin
     for i := 0 to Screen.FormCount -1 do
      if Screen.Forms[i].ClassType<>TMainF then
        if Screen.Forms[i].ClassType<>TLogF   then
//          if Screen.Forms[i].ClassType<>TCalendarF then
//              Screen.Forms[i].Close;
              Screen.FormCount;
end;
////////////////////////////////////////////////////////////////////////////////
function CheckKey(var Key: char;str:string):boolean;
begin
   result:=false;
   if str='n' then   //为数字
   begin
     if (key in ['0'..'9']) then
        result:=true;
   end
   else          //str='s'为字符
   begin
       if (key in ['a'..'z']) or (key in ['A'..'Z']) then
          result:=true;
   end;
end;


////////////////////////////////////////////////////////////////////////////////
//LISTBOX前面序号*************************************************************
procedure getOrder(ListB:TlistBox);
var
  i:integer;
  str:string;
  begin
    for i:=0 to ListB.Items.Count-1 do
    begin
      str:=ListB.Items.Strings[i];
      ListB.Items.Strings[i]:=inttostr(i+1)+')'+rightstr(str,length(str)-pos(')',str));
    end;
  end;


//清除文本框文本**************************************************************
function CClearData(form:TForm):boolean;
var
  I:integer;
begin
  result:=false;
    for i:=0 to form.ControlCount-1 do
    begin
      if form.Controls[i] is TEdit then
        (form.Controls[i] as TEdit).Text:=''
      else if form.Controls[i] is TComboBox then
        (form.Controls[i] as TComboBox).ItemIndex:=0
      else if form.Controls[i] is TMemo then
        (form.Controls[i] as TMemo).Text:='';
    end;
end;

//根据窗口类名建立窗口,如果窗口存在则只激活它 ********************************
procedure OpenForm(FormClass: TFormClass; var AForm;AOwner:TComponent=nil;modal:boolean=false);
var
  i: integer;
  Child:TForm;
begin
  for i := 0 to Screen.FormCount -1 do
      if Screen.Forms[i].ClassType=FormClass then
      begin
        Child:=Screen.Forms[i];
        if Child.WindowState=wsMinimized then
           Child.WindowState:=wsNormal;
        Child.BringToFront;
        Child.Setfocus;
        TForm(AForm):=Child;
        exit;
      end;
  Child:=TForm(FormClass.NewInstance);
  TForm(AForm):=Child;
  if not assigned(aowner) then aowner:=application;

  if modal then
  begin
    Child.Create(AOwner);
    child.Visible:=false;
    child.ShowModal;
    exit;
  end
  else
  begin
     Child.Create(AOwner);
     child.Show;
  end;
end;


//显示关于窗口(window about)
function ShowAbout():boolean;
var
  hIcon,hInst:integer;
  sappname,sappver:string;
begin
  sappname:='图书管理系统';
  sappver:=' version 1.0';
  hInst:=getwindowword(application.Handle,GWL_HINSTANCE);
  hIcon:=ExtractIcon(hInst,pchar(application.exename),0);
  Result:=boolean(shellabout(application.Handle,
    pchar(SAppName),pchar(SAppName+sappver),hicon));
end;

//可用资源
function GetMemoryInfo :integer;
var
  MS: TMemoryStatus;
begin
  MS.dwLength:=SizeOf(TMemoryStatus);
  GlobalMemoryStatus(MS);
  result:=MS.dwTotalPhys
end;
//获取系统信息
function GetOSInfo:string;
var
  Platform: string;
  BuildNumber: Integer;
begin
  case Win32Platform of
  VER_PLATFORM_WIN32_WINDOWS:
    begin
      Platform := 'Windows 95';
      BuildNumber := Win32BuildNumber and $0000FFFF;
    end;
  VER_PLATFORM_WIN32_NT:
    begin
      Platform := 'Windows NT';
      BuildNumber := Win32BuildNumber;
    end;
    else
    begin
      Platform := 'Windows';
      BuildNumber := 0;
    end;
  end;

  if(Win32Platform = VER_PLATFORM_WIN32_WINDOWS)
    or(Win32Platform = VER_PLATFORM_WIN32_NT) then
  begin
    if Win32CSDVersion = '' then
       result:=Format('%s%s  %d.%d (Build %d)',[Platform,#13,Win32MajorVersion,Win32MinorVersion,BuildNumber])
    else
       result:=Format('%s%s  %d.%d (Build %d: %s)',[Platform,#13,Win32MajorVersion,Win32MinorVersion, BuildNumber,Win32CSDVersion]);
     end else
       result:=Format('%s%s  %d.%d', [Platform,#13,Win32MajorVersion,Win32MinorVersion])
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -