ChangeNameAndPasswordFrm.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:4k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit ChangeNameAndPasswordFrm;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
- type
- TChangeNameAndPasswordForm = class(TForm)
- Label1: TLabel;
- EDName: TEdit;
- BTOK: TButton;
- BTCancel: TButton;
- GroupBox1: TGroupBox;
- Label3: TLabel;
- EDConfirmPassword: TEdit;
- EDPassword: TEdit;
- Label2: TLabel;
- Label4: TLabel;
- EDOldPassword: TEdit;
- Label5: TLabel;
- procedure FormShow(Sender: TObject);
- procedure EDNameChange(Sender: TObject);
- procedure BTOKClick(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure BTCancelClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- ChangeNameAndPasswordForm: TChangeNameAndPasswordForm;
- implementation
- uses RealMessengerImpl,RealMessengerUnit,Global;
- {$R *.dfm}
- procedure TChangeNameAndPasswordForm.FormShow(Sender: TObject);
- begin
- EDName.Text:=Me.Name;
- BTOK.Enabled:=False;
- end;
- procedure TChangeNameAndPasswordForm.EDNameChange(Sender: TObject);
- begin
- BTOK.Enabled:=True;
- end;
- procedure TChangeNameAndPasswordForm.BTOKClick(Sender: TObject);
- var
- CBChangeNameAndPassword:TCBChangeNameAndPassword;
- Buffer:Array[1..2048]of char;
- StartTicket:Cardinal;
- OldName:String;
- begin
- if Trim(EDName.Text)='' then
- begin
- MessageBox(Handle,'呢称不能为空!','提示',MB_ICONINFORMATION);
- Exit;
- end;
- if (Trim(EDOldPassword.Text)<>'') or (Trim(EDPassword.Text)<>'') or (Trim(EDConfirmPassword.Text)<>'') then
- begin
- if Trim(EDOldPassword.Text)<>Password then
- begin
- MessageBox(Handle,'原密码输入错误!','提示',MB_ICONINFORMATION);
- Exit;
- end;
- if Trim(EDPassword.Text)='' then
- begin
- MessageBox(Handle,'密码不能为空!','提示',MB_ICONINFORMATION);
- Exit;
- end;
- if not AnsiSameStr(Trim(EDPassword.Text),Trim(EDConfirmPassword.Text)) then
- begin
- MessageBox(Handle,'两次输入的密码不一致!','提示',MB_ICONINFORMATION);
- Exit;
- end;
- end;
- BTOK.Caption:='正在更新...';
- BTOK.Enabled:=False;
- BTCancel.Enabled:=False;
- CBChangeNameAndPassword.ID:=Me.ID;
- CBChangeNameAndPassword.Name:=Trim(EDName.Text);
- CBChangeNameAndPassword.Password:=Trim(EDPassword.Text);
- Buffer[1]:=skChangeNameAndPassword;
- CopyMemory(@Buffer[2],@CBChangeNameAndPassword,SizeOf(CBChangeNameAndPassword));
- try
- RealMessengerX.ClientTCP.WriteBuffer(Buffer,SizeOf(CBChangeNameAndPassword)+1,True);
- except
- MessageBox(Handle,'更改呢称/密码失败!','错误',MB_ICONERROR);
- BTOK.Caption:='更新';
- BTOK.Enabled:=True;
- BTCancel.Enabled:=True;
- Exit;
- end;
- //6秒内还未收到服务器发来的确认消息,则提示更新失败
- StartTicket:=0;
- OldName:=Me.Name;
- Me.Name:='正在更新呢称...';
- while StartTicket<200 do
- begin
- if Me.Name=Trim(EDName.Text) then
- begin
- if Trim(EDPassword.Text)<>'' then Password:=Trim(EDPassword.Text);
- MessageBox(Handle,'更改呢称/密码成功!','提示',MB_ICONINFORMATION);
- BTOK.Caption:='更新';
- BTOK.Enabled:=False;
- BTCancel.Enabled:=True;
- Close;
- Exit;
- end;
- Inc(StartTicket);
- Application.ProcessMessages;
- Sleep(30);
- end;
- Me.Name:=OldName;
- MessageBox(Handle,'更改呢称/密码失败(超时)!','错误',MB_ICONERROR);
- BTOK.Caption:='更新';
- BTOK.Enabled:=True;
- BTCancel.Enabled:=True;
- end;
- procedure TChangeNameAndPasswordForm.FormClose(Sender: TObject;
- var Action: TCloseAction);
- begin
- Action:=caFree;
- ChangeNameAndPasswordForm:=nil;
- end;
- procedure TChangeNameAndPasswordForm.BTCancelClick(Sender: TObject);
- begin
- Close;
- end;
- end.