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

📄 topview.~pas

📁 求是科技出版的《Delphi串口通信工程开发实例导航》所有的源代码。是一本很好的书。拿出来与大家共享。
💻 ~PAS
字号:
unit TopView;

interface

uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, CoreData, LeftView, Account, ImgList;

type
  TfrmTop = class(TFrame)
    tabAccount: TTabControl;
    lsvEmail: TListView;
    imlEmail: TImageList;
    procedure FrameResize(Sender: TObject);
    procedure lsvEmailClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure AddToMailList(lst : TList); overload;             // 将 lst 中的邮件添加到ListView中
    procedure AddToMailList(email : TEmailInfo); overload;      // 将 email 添加到 ListView 中
  end;

implementation

{$R *.dfm}

procedure TfrmTop.FrameResize(Sender: TObject);
begin
        if Boolean(tabAccount.Handle) then
        begin
                tabAccount.Left := 0;
                tabAccount.Top := 0;
                tabAccount.Width := self.Width;
                tabAccount.Height := self.Height;

                lsvEmail.Left := -4;
                lsvEmail.Top := 0;
                lsvEmail.Width := self.Width - 4;
                lsvEmail.Height := self.Height - 8;
        end;
end;

//
// 将 lst 中的邮件添加到 ListView 中
//
procedure TfrmTop.AddToMailList(lst: TList);
var
        i : integer;
        pEmail : ^TEmailInfo;
        item : TListItem;
begin
        for i := 0 to lst.Count - 1 do
        begin
                pEmail := lst.Items[i];
                item := lsvEmail.Items.Add();

                with pEmail^ do
                begin
                        item.Caption := m_From;
                        item.SubItems.Clear();
                        item.SubItems.Add(m_Subject);
                        item.SubItems.Add(m_Size);
                        item.SubItems.Add(m_Date);
                        if m_IsNew then
                                Item.ImageIndex := 0
                        else
                                Item.ImageIndex := 1;
                end;
        end;// finished all the new email
end;

//
// 将 email 加入到 ListView 中
//
procedure TfrmTop.AddToMailList(email: TEmailInfo);
var
        item : TListItem;
begin
        item := lsvEmail.Items.Add();

        with email do
        begin
                item.Caption := m_From;
                item.SubItems.Clear();
                item.SubItems.Add(m_Subject);
                item.SubItems.Add(m_Size);
                item.SubItems.Add(m_Date);
                if m_IsNew then
                        Item.ImageIndex := 0
                else
                        Item.ImageIndex := 1;
        end;
end;

//
// 邮件列表框选定项发改变触发此事件
//
procedure TfrmTop.lsvEmailClick(Sender: TObject);
var
        pAccount : ^TAccountInfo;
        pEmail : ^TEmailInfo;
begin
        if lsvEmail.Selected = nil then
                exit;
        if Account.m_lstAccount = nil then
                exit;
        pAccount := Account.m_lstAccount.Items[self.tabAccount.TabIndex];
        if pAccount^.m_lstEmail = nil then
                exit;
        pEmail := pAccount^.m_lstEmail.Items[lsvEmail.Selected.index];
        pEmail^.m_IsNew := False;
        lsvEmail.Selected.ImageIndex := 1;
end;

end.

⌨️ 快捷键说明

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