【delphi开源代码栏目提醒】:网学会员--在 delphi开源代码编辑为广大网友搜集整理了:Account.pas绩等信息,祝愿广大网友取得需要的信息,参考学习。
unit Account;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Buttons, Contnrs, CoreData, iniFiles;
type
TfrmAccount = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
edtAccount: TEdit;
Label2: TLabel;
edtServer: TEdit;
Label3: TLabel;
edtPort: TEdit;
Label4: TLabel;
edtUser: TEdit;
Label5: TLabel;
edtPwd: TEdit;
Label6: TLabel;
edtMobile: TEdit;
btnAdd: TButton;
btnModify: TButton;
btnDelete: TBitBtn;
btnClose: TBitBtn;
lstAccount: TListView;
chkSendSMS: TCheckBox;
procedure btnAddClick(Sender: TObject);
procedure btnModifyClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure lstAccountChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure FormShow(Sender: TObject);
procedure lstAccountClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure ReadAccountInfo();
procedure SaveAccountInfo();
procedure ReleaseAll();
public
{ Public declarations }
end;
var
frmAccount: TfrmAccount; // Account 对话话框
m_lstAccount : TList; // 用来存储当前账号的链表
m_IsChanged : Boolean; // 标志账号信息是否改变
implementation
{$R *.dfm}
//
// 添加按钮单击事件处理程序
//
procedure TfrmAccount.btnAddClick(Sender: TObject);
var
pAccount : ^TAccountInfo;
Item : TListItem;
begin
//
// 分配空间
//
if m_lstAccount = nil then
m_lstAccount := TList.Create();
// 确保各文本框已经添写内容
if (edtAccount.Text = '') or (edtServer.Text = '')
or (edtport.Text = '') or (edtUser.Text = '')
or (edtPwd.Text = '') or (edtMobile.Text = '') then
exit;
//
// 初始化pAccount,并加入链表 m_lstAccount 中
//
new(pAccount);
pAccount^.m_Account := edtAccount.Text;
pAccount^.m_Server := edtServer.Text;
pAccount^.m_Port := edtPort.Text;
pAccount^.m_User := edtUser.Text;
pAccount^.m_Pwd := edtPwd.Text;
pAccount^.m_Mobile := edtMobile.Text;
pAccount^.m_SendToMobile := chkSendSMS.Checked;
pAccount^.m_lstEmail := TList.Create();
m_lstAccount.Add(pAccount);
//
// 加入账号显示列表框中
//
item := lstAccount.Items.Add();
with pAccount^ do
begin
item.Caption := m_Account;
item.SubItems.Clear();
item.SubItems.Add(m_Server);
item.SubItems.Add(m_User);
item.SubItems.Add(m_Mobile);
end;
//
// 设置修改标志
//
m_IsChanged := true;
end;
//
// 修改按钮单击事件处理程序
//
procedure TfrmAccount.btnModifyClick(Sender: TObject);
var
pAccount : ^TAccountInfo;
Item : TListItem;
begin
// 找到选中的列表项
Item := lstAccount.Selected;
if Item = nil then
exit;
// 确保各文本框已经添写内容
if (edtAccount.Text = '') or (edtServer.Text = '')
or (edtport.Text = '') or (edtUser.Text = '')
or (edtPwd.Text = '') or (edtMobile.Text = '') then
exit;
//
// 获取 m_lstAccount 中对应的pAccount,并更新之
//
pAccount := m_lstAccount.Items[lstAccount.Selected.Index];
pAccount^.m_Account := edtAccount.Text;
pAccount^.m_Server := edtServer.Text;
pAccount^.m_Port := edtPort.Text;
pAccount^.m_User := edtUser.Text;
pAccount^.m_Pwd := edtPwd.Text;
pAccount^.m_SendToMobile := chkSendSMS.Checked;
pAccount^.m_Mobile := edtMobile.Text;
//
// 更新账号显示列表框的显示
//
with pAccount^ do
begin
item.Caption := m_Account;
item.SubItems.Clear();
item.SubItems.Add(m_Server);
item.SubItems.Add(m_User);
item.SubItems.Add(m_Mobile);
end;
//
// 设置修改标志
//
m_IsChanged := true;
end;
//
// 删除按钮单击事件处理程序
//
procedure TfrmAccount.btnDeleteClick(Sender: TObject);
var
pAccount : ^TAccountInfo;
Item : TListItem;
SelIndex : integer;
begin
// 找到选中的列表项
Item := lstAccount.Selected;
SelIndex := lstAccount.ItemIndex;
if Item = nil then
exit;
//
// 获取 m_lstAccount 中对应的pAccount,并删除之
//
pAccount := m_lstAccount.Items[lstAccount.Selected.Index];
m_lstAccount.Delete(lstAccount.Selected.Index);
dispose(pAccount);
//
// 更新账号显示列表框的显示
//
//lstAccount.DeleteSelected();
//if SelIndex > 0 then
// lstAccount.ItemIndex := SelIndex - 1;
lstAccount.Items.Count;
lstAccount.Items[SelIndex].Delete;
//lstAccount.Items.Delete(SelIndex);
//
// 设置修改标志
//
m_IsChanged := true;
end;
//
// 列表选择发生改变时处理程序
//
procedure TfrmAccount.lstAccountChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
var
pAccount : ^TAccountInfo;
begin
//
// 获取 m_lstAccount 中对应的pAccount,并删除之
//
if lstAccount.Selected = nil then
exit;
pAccount := m_lstAccount.Items[lstAccount.Selected.index];
//
// 更新账号显示列表框的显示
//
with pAccount^ do
begin
edtAccount.Text := m_Account;
edtServer.Text := m_Server;
edtPort.Text := m_Port;
edtUser.Text := m_User;
edtPwd.Text := m_Pwd;
edtMobile.Text := m_Mobile;
chkSendSMS.Checked := m_SendToMobile;
end;
end;
//
// 窗体显示时处理事件
//
procedure TfrmAccount.FormShow(Sender: TObject);
var
pAccount : ^TAccountInfo;
Item : TListItem;
i : integer;
begin
//
// 设置修改标志
//
m_IsChanged := false;
if m_lstAccount = nil then
exit;
if lstAccount.Items.Count > 0 then
exit;
//
// 遍历 m_lstAccount 所有账号
//
for i := 0 to m_lstAccount.Count - 1 do
begin
pAccount := m_lstAccount.Items[i];
//
// 更新账号显示列表框的显示
//
item := lstAccount.Items.Add();
with pAccount^ do
begin
item.Caption := m_Account;
item.SubItems.Clear();
item.SubItems.Add(m_Server);
item.SubItems.Add(m_User);
item.SubItems.Add(m_Mobile);
end;
end;
end;
//
// 列表框单击处理事件
//
procedure TfrmAccount.lstAccountClick(Sender: TObject);
var
pAccount : ^TAccountInfo;
begin
if lstAccount.Selected = nil then
exit;
//
// 获取 m_lstAccount 中对应的pAccount,并删除之
//
pAccount := m_lstAccount.Items[lstAccount.Selected.index];
//
// 更新账号显示列表框的显示
//
with pAccount^ do
begin
edtAccount.Text := m_Account;
edtServer.Text := m_Server;
edtPort.Text := m_Port;
edtUser.Text := m_User;
edtPwd.Text := m_Pwd;
edtMobile.Text := m_Mobile;
chkSendSMS.Checked := m_SendToMobile;
end;
end;
//
// 读取配置文件中的账号和邮件信息
//
procedure TfrmAccount.ReadAccountInfo;
var
Configini: TIniFile;
Account_num : integer;
i : integer;
stream : TStringStream;
FilePath : string;
pAccount : ^TAccountInfo;
pEmail : ^TEmailInfo;
DataFile : File of TEmailInfo;
begin
FilePath := ExtractFilePath(ParamStr(0));
if not FileExists(FilePa
上一篇:
accident_info_unit.pas
下一篇:
让我掉下眼泪的