国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

合理應用用戶登錄界面,用戶登錄時不必創建其他窗體

2019-11-18 18:14:48
字體:
來源:轉載
供稿:網友

/////////////////////  (一)項目文件  test.dPR //////////////////////
program SerialGet;

uses
  Forms,
  UMain in 'UMain.pas' {frmMain},
  ULogin in 'ULogin.pas' {frmLogin},
  UDataModule in 'UDataModule.pas' {DataModule1: TDataModule},

{$R *.res}

begin
  application.Initialize;

  if CreateMutex then                 //創建句柄,判斷此應用程序是否在運行
  begin
    //調用全局函數,創建并顯示登陸界面
    if doLogin then                   //登陸成功
    begin
      Application.CreateForm(TfrmMain, frmMain);
      //數據模塊文件不須在這兒創建,因為 ULogin.pas 中已創建
      //Application.CreateForm(TDataModule1, DataModule1);
      Application.Run;
    end else                          //登陸不成功
    begin
      try
        DataModule1.free;
        Application.terminate;
      except
      end;
    end;
  end else
  begin
    DestroyMutex;                     //釋放句柄
  end;
end.

////////////////  (二)登陸窗體 ULogin.pas  ULogin.dfm //////////////////
unit ULogin;

interface
uses ......
type
  ... ... ...
  private
    function checkPsw:integer;
  public
  end;

var
  frmLogin: TfrmLogin;

  function doLogIn:boolean;          // 全項目公用函數
  function CreateMutex: Boolean;     // 全項目公用函數
  procedure DestroyMutex;            // 全項目公用函數

implementation
uses UDataModule;  //引用數據模塊
var Mutex: hWnd;

{$R *.dfm}

function doLogIn:boolean;                 //由項目文件調用此函數
begin
  with TfrmLogin.create(application) do   //創建并顯示登陸界面
  begin
    //窗體的ShowModal屬性
    if ShowModal = mrok then result := true else result := false;
    free;
  end;
end;

procedure DestroyMutex;
begin
  if Mutex <> 0 then CloseHandle(Mutex);
end;

function CreateMutex: Boolean;
var
  PrevInstHandle: THandle;
  APPTitle: PChar;
begin
  AppTitle := StrAlloc(100);
  StrPCopy(AppTitle, Application.Title);
  Result := True;
  Mutex := Windows.CreateMutex(nil, False, AppTitle);
  if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then begin
    Result := False;
    SetWindowText(Application.Handle, '');
    PrevInstHandle := FindWindow(nil, AppTitle);
    if PrevInstHandle <> 0 then begin
      if IsIconic(PrevInstHandle) then
        ShowWindow(PrevInstHandle, SW_RESTORE)
      else
        BringWindowToTop(PrevInstHandle);
      SetForegroundWindow(PrevInstHandle);
    end;
    if Mutex <> 0 then Mutex := 0;
  end;
  StrDispose(AppTitle);
end;

// -1: 密碼不對  1:數據庫不對  2:沒有此用戶  3:合法
function TfrmLogin.checkPsw:integer;
var name,sPsw,SQL,sValue:string;
begin
  Application.CreateForm(TDataModule1, DataModule1);  //此處創建了數據模塊
  if not DataModule1.ConnOK then
  begin result := 1;   exit;  end;

  name := lowercase(editName.text);  //文本框
  sPsw := lowercase(editPass.text);  //文本框
  sql := 'select * from maker where name="'+name+'"';
  if openSQL(SQL,DataModule1.dsDataSet) <=0 then
  begin result := 2; exit;  end;

  DataModule1.dsDataSet.First ;
  sValue := lowercase(DataModule1.dsDataSet.fieldbyName('loginPsw').asString);
  if sValue<>sPsw then result := -1 else result := 3;
end;

/////////////////////  (三)數據模塊 UDataModule.pas //////////////////////
... ... ... ...
type
  public
    ConnOK:boolean;
  end;
var
  DataModule1: TDataModule1;
  function OpenSQL(s: string;query:TADODataSet):integer;
  function DoSQL(s: string;query:TADOQuery):boolean;
 
implementation

{$R *.dfm}

procedure TDataModule1.DataModuleCreate(Sender: TObject); //連接ADOConnection
var SQL,pwd:string;
begin
  try
    pwd := 'deliSerial';
    SQL := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
         extractfilepath(paramstr(0))+'SerialInfo.mdb'+
         ';Persist Security Info=False;'  +
         'Jet OLEDB:Database PassWord="'+pwd+'"';
    ADOConnection1.Connected := false;
    ADOConnection1.ConnectionString := SQL;
    ADOConnection1.Connected := true;
    ConnOK:=true;
  except
    ConnOK:=false;
  end;
end;

function OpenSQL(s: string;query:TADODataSet):integer; //查詢SQL
var old_Cursor:TCursor;
begin
  old_Cursor:=screen.cursor;
  screen.cursor:=crSQLWait;
  try
    try
      with query do
      begin
        close; commandtext:=s; open;
        result:=query.recordcount;       //返回結果集記錄數
      end;
    except
     result:=0;
    end;
  finally
    screen.cursor:=old_Cursor;
  end;
end;

function DoSQL(s: string;query:TADOQuery):boolean;  //運行 SQL
var old_Cursor:TCursor;
begin
  result:=true;
  old_Cursor:=screen.cursor;
  screen.cursor:=crSQLWait;
  try
    try
      with query do
      begin
        close; SQL.Clear; SQL.Add(s); ExecSQL;
      end;
    except
      result:=false;
    end;
  finally
    screen.cursor:=old_Cursor;
  end;
end;


上一篇:ADO帶密碼的數據連接、查詢一個記錄集、執行一SQL語句

下一篇:選擇一個網路鄰居

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 衡水市| 秦皇岛市| 阜康市| 曲阳县| 调兵山市| 乌审旗| 汾阳市| 塔城市| 五华县| 遂平县| 虎林市| 哈巴河县| 宜川县| 万州区| 鄄城县| 定西市| 锡林郭勒盟| 平潭县| 婺源县| 齐齐哈尔市| 苍南县| 句容市| 皋兰县| 沂南县| 大埔区| 美姑县| 延庆县| 新泰市| 镇坪县| 浙江省| 乌审旗| 乡宁县| 海丰县| 霍邱县| 武义县| 五大连池市| 新龙县| 新余市| 晋城| 修武县| 察哈|