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

📄 udemo.pas

📁 山东深思二代阅读设备的使用演示程序
💻 PAS
字号:
unit Udemo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, StdCtrls, Clipbrd;

const WM_MY_TEST=Wm_User+200;
const WM_MY_ENCODEOK=Wm_User+201;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label14: TLabel;
    Label10: TLabel;
    Label9: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label2: TLabel;
    Image1: TImage;
    esName: TLabel;
    esSex: TLabel;
    esFolk: TLabel;
    esBirth: TLabel;
    esAddr: TLabel;
    esID: TLabel;
    BitBtn1: TBitBtn;
    Timer1: TTimer;
    Label3: TLabel;
    Label4: TLabel;
    esIssue: TLabel;
    esBegin: TLabel;
    esEnd: TLabel;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    BitBtn2: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
    Function InitComm(iPort:integer):integer; stdcall;far; External 'termb.dll'; //
    Function CloseComm:integer; stdcall;far; External 'termb.dll'; //
    Function Authenticate:integer; stdcall;far; External 'termb.dll'; //
    Function Read_Content(Act:integer):integer; stdcall;far; External 'termb.dll'; //

var
  Form1: TForm1;
    FOLK:array[1..56]of string;

    nRet:integer;
    bRun:boolean;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
    ExtendedStyle : Integer;
    i,j:integer;
    sys_exe:String;
begin
    bRun:=False;

    //PostMessage(
        esName.Caption:='';
        esSex.Caption:='';
        esFolk.Caption:= '';
        esBirth.Caption:='';
        esAddr.Caption:='';
        esID.Caption:='';
        esIssue.Caption:='';
        esBegin.Caption:='';
        esEnd.Caption:='';

        esName.Refresh;
        esSex.Refresh;
        esFolk.Refresh;
        esBirth.Refresh;
        esAddr.Refresh;
        esID.Refresh;
        esIssue.Refresh;
        esBegin.Refresh;
        esEnd.Refresh;
    //-------------------------------------

    //ExtendedStyle := GetWindowLong (Application.Handle, GWL_EXSTYLE);
    //SetWindowLong(Application.Handle, GWL_EXSTYLE, ExtendedStyle OR WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW);

    Image1.Picture.Bitmap.TransparentColor:=clNone;

    FOLK[1]:='汉族'		;
    FOLK[2]:='蒙古族'        ;
    FOLK[3]:='回族'          ;
    FOLK[4]:='藏族'          ;
    FOLK[5]:='维吾尔族'      ;
    FOLK[6]:='苗族'          ;
    FOLK[7]:='彝族'          ;
    FOLK[8]:='壮族'          ;
    FOLK[9]:='布依族';          //'满族'          ;
    FOLK[10]:='朝鲜族';         //'侗族'          ;
    FOLK[11]:='满族';           //'瑶族'          ;
    FOLK[12]:='侗族';           //'白族'          ;
    FOLK[13]:='瑶族';           //'土家族'        ;
    FOLK[14]:='白族';           //'哈尼族'        ;
    FOLK[15]:='土家族';         //'哈萨克族'      ;
    FOLK[16]:='哈尼族';         //'傣族'          ;
    FOLK[17]:='哈萨克族';       //'佤族'          ;
    FOLK[18]:='傣族';           //'畲族'          ;
    FOLK[19]:='黎族';           //'高山族'        ;
    FOLK[20]:='傈僳族';         //'拉祜族'        ;
    FOLK[21]:='佤族';           //'水族'          ;
    FOLK[22]:='畲族';           //'东乡族'        ;
    FOLK[23]:='高山族';         //'纳西族'        ;
    FOLK[24]:='拉祜族';         //'景颇族'        ;
    FOLK[25]:='水族';           //'达斡尔族'      ;
    FOLK[26]:='东乡族';         //'仫佬族'        ;
    FOLK[27]:='纳西族';         //'羌族'          ;
    FOLK[28]:='景颇族';         //'布朗族'        ;
    FOLK[29]:='柯尔克孜族';     //'撒拉族'        ;
    FOLK[30]:='土族';           //'毛南族'        ;
    FOLK[31]:='达斡尔族';       //'仡佬族'        ;
    FOLK[32]:='仫佬族';         //'锡伯族'        ;
    FOLK[33]:='羌族';           //'塔吉克族'      ;
    FOLK[34]:='布朗族';         //'怒族'          ;
    FOLK[35]:='撒拉族';         //'乌孜别克族'    ;
    FOLK[36]:='毛南族';         //'俄罗斯族'      ;
    FOLK[37]:='仡佬族';         //'鄂温克族'      ;
    FOLK[38]:='锡伯族';     //'德昂族'        ;
    FOLK[39]:='阿昌族';         //'保安族'        ;
    FOLK[40]:='普米族';         //'裕固族'        ;
    FOLK[41]:='塔吉克族';       //'独龙族'        ;
    FOLK[42]:='怒族';           //'鄂伦春族'      ;
    FOLK[43]:='乌孜别克族';     //'赫哲族'        ;
    FOLK[44]:='俄罗斯族';       //'门巴族'        ;
    FOLK[45]:='鄂温克族';       //'珞巴族'        ;
    FOLK[46]:='德昂族'; //崩龙族      //'基诺族'        ; 德昂族原称“崩龙”,这一族称始于清代,系他称,解放后统称崩龙族。在本民族的要求下,1985年9月经国务院批准改称为德昂族。
    FOLK[47]:='保安族';         //'朝鲜族'        ;
    FOLK[48]:='裕固族';         //'傈僳族'        ;
    FOLK[49]:='京族';           //'普米族'        ;
    FOLK[50]:='塔塔尔族'      ;
    FOLK[51]:='独龙族';         //'布依族'        ;
    FOLK[52]:='鄂伦春族';       //'黎族'          ;
    FOLK[53]:='赫哲族';         //'柯尔克孜族'    ;
    FOLK[54]:='门巴族';         //'阿昌族'        ;
    FOLK[55]:='珞巴族';         //'京族'          ;
    FOLK[56]:='基诺族';         //'土族'          ;

    //FOLK[97]:='其他';
    //FOLK[98]:='外国血统';




end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    if Timer1.Enabled then
    begin
        CloseComm;
    end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
    info:array[0..255] of BYTE;
    uniData:array[1..256] of BYTE;
    ss:string;
    hFile:THandle;  //文件句柄
    nRead:DWORD;  //读取字节数
    i,j:integer;

    rect:Trect;
begin
    if not bRun then
    begin
        //
        Timer1.Enabled:=False;
      Try
        nRet:=Authenticate;
        if nRet=1 then
        begin
            //清除信息显示
            esName.Caption:='';
            esSex.Caption:='';
            esFolk.Caption:= '';
            esBirth.Caption:='';
            esAddr.Caption:='';
            esID.Caption:='';
            esIssue.Caption:='';
            esBegin.Caption:='';
            esEnd.Caption:='';

            esName.Refresh;
            esSex.Refresh;
            esFolk.Refresh;
            esBirth.Refresh;
            esAddr.Refresh;
            esID.Refresh;
            esIssue.Refresh;
            esBegin.Refresh;
            esEnd.Refresh;

            //Image1.Picture.Bitmap.FreeImage;
            rect.Left:=0;
            rect.Top:=0;
            rect.Right:=102;
            rect.Bottom:=126;
            Image1.Canvas.FillRect(rect);
            Image1.Refresh;

            //验证卡成功
            //读基本信息
            nRet:=Read_Content(1);
            if nRet=1 then
            begin
                //读卡成功
                ss:=ExtractFilePath(Application.ExeName)+'wz.txt';
                if fileExists(ss) then
                begin
                     hfile:= CreateFile(PChar(ss),
                                   GENERIC_WRITE or GENERIC_READ,
                                   0,
                                   Nil,
                                   OPEN_EXISTING,
                                   FILE_ATTRIBUTE_NORMAL,
                                   0);
                    ReadFile(hfile,info,256, nRead, nil);
                    CloseHandle(hfile);//关闭文件
                    if nRead=256 then
                    begin
                        //Showmessage('文件读入成功!');
                        //========================================
                        j:=0;
                        //Name
                        for i:=1 to 100 do uniData[i]:=$0;
                        for i:=1 to 30 do
                        begin
                            uniData[i]:=info[j+i-1];
                            //esName.Caption:=esName.Caption+char(info[j+i-1]);
                        end;
                        esName.Caption:=trim(WideCharLenToString(PWideChar(@uniData),15));
                        //Sex
                        for i:=1 to 100 do uniData[i]:=$0;
                        j:=30;
                        for i:=1 to 2 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esSex.Caption:=trim(WideCharLenToString(PWideChar(@uniData),1));
                        if esSex.Caption='1' then
                            esSex.Caption:='男'
                        else
                            esSex.Caption:='女';

                        //Folk
                        j:=32;
                        for i:=1 to 4 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esFolk.Caption:=trim(WideCharLenToString(PWideChar(@uniData),2));
                        esFolk.Caption:=FOLK[strtoint(esFolk.Caption)];
                        //BirthDay
                        j:=36;
                        for i:=1 to 16 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esBirth.Caption:=trim(WideCharLenToString(PWideChar(@uniData),8));
                        //Addr
                        j:=52;
                        for i:=1 to 70 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esAddr.Caption:=trim(WideCharLenToString(PWideChar(@uniData),35));
                        //ID
                        j:=122;
                        for i:=1 to 36 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esID.Caption:=trim(WideCharLenToString(PWideChar(@uniData),18));
                        //Issue
                        j:=158;
                        for i:=1 to 30 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esIssue.Caption:=trim(WideCharLenToString(PWideChar(@uniData),15));
                        //IssueBegin
                        j:=188;
                        for i:=1 to 16 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esBegin.Caption:=trim(WideCharLenToString(PWideChar(@uniData),8));
                        //IssueEnd
                        j:=204;
                        for i:=1 to 16 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        esEnd.Caption:=trim(WideCharLenToString(PWideChar(@uniData),8));
                        {j:=220;
                        for i:=1 to 70 do
                        begin
                            uniData[i]:=info[j+i-1];
                        end;
                        }
                        Try
                            Image1.Picture.Bitmap.LoadFromFile('zp.bmp');
                        except
                        end;
                        //WinExec(

                    end;
                end
                else
                begin
                   // nRead:=0;
                   //文件不存在,读卡不成功
                end;
            end
            else if nRet=-1 then
            begin
              ShowMessage('相片解码错误');
            end
            else if nRet=-2 then
            begin
              ShowMessage('wlt文件后缀错误');
            end
            else if nRet=-3 then
            begin
              ShowMessage('wlt文件打开错误');
            end
            else if nRet=-4 then
            begin
              ShowMessage('wlt文件格式错误');
            end
            else if nRet=-5 then
            begin
              ShowMessage('软件未授权');
            end
            else if nRet=-6 then
            begin
              ShowMessage('设备连接错误');
            end;
        end
        else
        begin
            //验证卡失败
        end;
      except
      end;
        Timer1.Enabled:=True;
    end;

    //PostMessage(
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  MyFormat : Word;
  Bitmap : TBitMap;
  AData : THandle;
  APalette : HPALETTE;
begin
  Bitmap := TBitmap.Create;
  try
    Image1.Picture.Bitmap.LoadFromFile('zp.bmp');
    Image1.Picture.Bitmap.SaveToClipBoardFormat(MyFormat, AData,  APalette);
    ClipBoard.SetAsHandle(MyFormat,AData);
  finally
    Bitmap.Free;
  end;

    //PostMessage(HWND_BROADCAST,WM_MY_TEST,0,0);
    //Image1.Picture.Bitmap.SaveToClipboardFormat();
end;


procedure TForm1.BitBtn2Click(Sender: TObject);
begin
    if not Timer1.Enabled then
    begin
        if RadioGroup1.ItemIndex+1 < 5 then
        begin
            nRet:=InitComm(RadioGroup1.ItemIndex+1);  //打开串口 1
            if nRet=1 then
            begin
                Timer1.Enabled:=True;
            end;
        end
        else
        begin
            nRet:=InitComm(1001);  //打开串口 1
            if nRet=1 then
            begin
                Timer1.Enabled:=True;
            end;
        end;
    end
    else
    begin
        Timer1.Enabled:=False;
        nRet:=CloseComm;
    end;
    if Timer1.Enabled then
    begin
        BitBtn2.Caption:='断开连接';
    end
    else
    begin
        BitBtn2.Caption:='连  接';
    end;
end;

end.

⌨️ 快捷键说明

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