www.pudn.com > 200589952618.rar > loginformpas.pas
unit loginformpas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList, ComCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, mytype, myconst, mainformpas, TCPthreadpas;
type
Tloginform = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
username: TEdit;
passwd: TEdit;
GroupBox2: TGroupBox;
hostbox: TComboBox;
Button1: TButton;
CheckBox1: TCheckBox;
Button2: TButton;
GroupBox3: TGroupBox;
Label3: TLabel;
email: TEdit;
facelist: TComboBoxEx;
ImageReg: TImageList;
Label4: TLabel;
procedure Button2Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
login: boolean;
{ Public declarations }
end;
var
loginform: Tloginform;
implementation
{$R *.dfm}
procedure Tloginform.Button2Click(Sender: TObject);
begin
self.Close;
end;
procedure Tloginform.CheckBox1Click(Sender: TObject);
var
i: integer;
begin
if TCheckBox(Sender).Checked then
begin
self.Width := 449;
self.Button1.Caption := '注册';
facelist.ItemsEx.Clear;
for i := 0 to 84 do
begin
with facelist.ItemsEx.Add do imageindex := i;
end;
facelist.ItemIndex := 0;
end
else
begin
self.Width := 283;
self.Button1.Caption := '登陆';
end;
end;
procedure Tloginform.Button1Click(Sender: TObject);
var
userdata: Ruserdata;
ctext: Rcommandtext;
st: string;
begin
if not mainform.IdTCPClient1.Connected then
begin
mainform.IdTCPClient1.Host := hostbox.Text;
try
mainform.IdTCPClient1.Connect();
except
on e: exception do
begin
showmessage('无法连接服务器,请稍后重试');
exit;
end;
end;
end;
///登陆
if TButton(Sender).Caption = '登陆' then
begin
ctext.command := Clogin;
userdata.username := username.Text;
userdata.passwd := passwd.Text;
mainform.IdTCPClient1.WriteBuffer(ctext, sizeof(ctext));
mainform.IdTCPClient1.WriteBuffer(userdata, sizeof(userdata));
st := mainform.IdTCPClient1.ReadLn();
if st <> '用户名或密码不符。' then
begin
self.login := True;
mainform.user.username := username.Text;
mainform.tcp1 := Ttcpthread.Create(True);
mainform.tcp1.user.username := username.Text;
mainform.tcp1.user.face := strtoint(st);
self.Close;
end
else showmessage(st);
end;
///注册
if TButton(Sender).Caption = '注册' then
begin
ctext.command := Creg;
userdata.username := username.Text;
userdata.passwd := passwd.Text;
userdata.email := email.Text;
userdata.face := facelist.ItemIndex;
if (length(userdata.username) > 0) and (length(userdata.passwd) > 0) and (length(userdata.email) > 0) then
begin
mainform.IdTCPClient1.WriteBuffer(ctext, sizeof(ctext));
mainform.IdTCPClient1.WriteBuffer(userdata, sizeof(userdata));
st := mainform.IdTCPClient1.ReadLn();
showmessage(st);
end
else
begin
showmessage('注册信息不完整');
end;
end;
end;
procedure Tloginform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not self.login then
Application.Terminate;
end;
end.