ChangeNameAndPasswordFrm.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit ChangeNameAndPasswordFrm;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, ExtCtrls;
  6. type
  7.   TChangeNameAndPasswordForm = class(TForm)
  8.     Label1: TLabel;
  9.     EDName: TEdit;
  10.     BTOK: TButton;
  11.     BTCancel: TButton;
  12.     GroupBox1: TGroupBox;
  13.     Label3: TLabel;
  14.     EDConfirmPassword: TEdit;
  15.     EDPassword: TEdit;
  16.     Label2: TLabel;
  17.     Label4: TLabel;
  18.     EDOldPassword: TEdit;
  19.     Label5: TLabel;
  20.     procedure FormShow(Sender: TObject);
  21.     procedure EDNameChange(Sender: TObject);
  22.     procedure BTOKClick(Sender: TObject);
  23.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  24.     procedure BTCancelClick(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.   public
  28.     { Public declarations }
  29.   end;
  30. var
  31.   ChangeNameAndPasswordForm: TChangeNameAndPasswordForm;
  32. implementation
  33. uses RealMessengerImpl,RealMessengerUnit,Global;
  34. {$R *.dfm}
  35. procedure TChangeNameAndPasswordForm.FormShow(Sender: TObject);
  36. begin
  37.   EDName.Text:=Me.Name;
  38.   BTOK.Enabled:=False;
  39. end;
  40. procedure TChangeNameAndPasswordForm.EDNameChange(Sender: TObject);
  41. begin
  42.   BTOK.Enabled:=True;
  43. end;
  44. procedure TChangeNameAndPasswordForm.BTOKClick(Sender: TObject);
  45. var
  46.   CBChangeNameAndPassword:TCBChangeNameAndPassword;
  47.   Buffer:Array[1..2048]of char;
  48.   StartTicket:Cardinal;
  49.   OldName:String;
  50. begin
  51.   if Trim(EDName.Text)='' then
  52.   begin
  53.     MessageBox(Handle,'呢称不能为空!','提示',MB_ICONINFORMATION);
  54.     Exit;
  55.   end;
  56.   if (Trim(EDOldPassword.Text)<>'') or (Trim(EDPassword.Text)<>'') or (Trim(EDConfirmPassword.Text)<>'')  then
  57.   begin
  58.     if Trim(EDOldPassword.Text)<>Password then
  59.     begin
  60.       MessageBox(Handle,'原密码输入错误!','提示',MB_ICONINFORMATION);
  61.       Exit;
  62.     end;
  63.     
  64.     if Trim(EDPassword.Text)='' then
  65.     begin
  66.       MessageBox(Handle,'密码不能为空!','提示',MB_ICONINFORMATION);
  67.       Exit;
  68.     end;
  69.     
  70.     if not AnsiSameStr(Trim(EDPassword.Text),Trim(EDConfirmPassword.Text)) then
  71.     begin
  72.       MessageBox(Handle,'两次输入的密码不一致!','提示',MB_ICONINFORMATION);
  73.       Exit;
  74.     end;
  75.   end;
  76.   BTOK.Caption:='正在更新...';
  77.   BTOK.Enabled:=False;
  78.   BTCancel.Enabled:=False;
  79.   CBChangeNameAndPassword.ID:=Me.ID;
  80.   CBChangeNameAndPassword.Name:=Trim(EDName.Text);
  81.   CBChangeNameAndPassword.Password:=Trim(EDPassword.Text);
  82.   Buffer[1]:=skChangeNameAndPassword;
  83.   CopyMemory(@Buffer[2],@CBChangeNameAndPassword,SizeOf(CBChangeNameAndPassword));
  84.   try
  85.     RealMessengerX.ClientTCP.WriteBuffer(Buffer,SizeOf(CBChangeNameAndPassword)+1,True);
  86.   except
  87.     MessageBox(Handle,'更改呢称/密码失败!','错误',MB_ICONERROR);
  88.     BTOK.Caption:='更新';
  89.     BTOK.Enabled:=True;
  90.     BTCancel.Enabled:=True;
  91.     Exit;
  92.   end;
  93.   //6秒内还未收到服务器发来的确认消息,则提示更新失败
  94.   StartTicket:=0;
  95.   OldName:=Me.Name;
  96.   Me.Name:='正在更新呢称...';
  97.   while StartTicket<200 do
  98.   begin
  99.     if Me.Name=Trim(EDName.Text) then
  100.     begin
  101.       if Trim(EDPassword.Text)<>'' then Password:=Trim(EDPassword.Text);
  102.       MessageBox(Handle,'更改呢称/密码成功!','提示',MB_ICONINFORMATION);
  103.       BTOK.Caption:='更新';
  104.       BTOK.Enabled:=False;
  105.       BTCancel.Enabled:=True;
  106.       Close;
  107.       Exit;
  108.     end;
  109.     Inc(StartTicket);
  110.     Application.ProcessMessages;
  111.     Sleep(30);
  112.   end;
  113.   Me.Name:=OldName;
  114.   MessageBox(Handle,'更改呢称/密码失败(超时)!','错误',MB_ICONERROR);
  115.   BTOK.Caption:='更新';
  116.   BTOK.Enabled:=True;
  117.   BTCancel.Enabled:=True;
  118. end;
  119. procedure TChangeNameAndPasswordForm.FormClose(Sender: TObject;
  120.   var Action: TCloseAction);
  121. begin
  122.   Action:=caFree;
  123.   ChangeNameAndPasswordForm:=nil;
  124. end;
  125. procedure TChangeNameAndPasswordForm.BTCancelClick(Sender: TObject);
  126. begin
  127.   Close;
  128. end;
  129. end.