Delphi 模拟分页效果 控件批量赋值

本文介绍了一个使用Delphi创建的界面,展示了如何通过12个显示模板来呈现员工信息,包括头像、性别图标和姓名。项目涉及多个单元,如uVar用于路径管理,uObj用于对象操作,以及uFrmMain用于主窗体逻辑。系统能够从指定目录读取图片数据,按每页12条记录进行分页显示,并提供了导航按钮以切换页面。

1. 设计界面 12个显示模板 每个模板两个TImage(一个头像, 一个性别), 一个TLabel(姓名).

    命名带有一定规律:

    头像的TImage的Name从 img_01 ~ img_12

    性别的TImage的Name从 isex_01 ~ isex_12

    姓名的TLable的Name从  lbl_01 ~ lbl_12

2. 新建单元uVar.pas

unit uVar;

interface

uses
  SysUtils, Forms;

type
  TAppParams = class
  public
    class function AppPath: string;
    class function AppName: string;
  end;

  TFilePath= class(TAppParams)
  public
    class function PngPath: string;
    class function ImgPath: string;
  end;

implementation

{ TAppPara }

class function TAppParams.AppName: string;
begin
  Result := ExtractFileName(Application.ExeName);
end;

class function TAppParams.AppPath: string;
begin
  Result := ExtractFilePath(Application.ExeName);
end;

{ TFilePath }

class function TFilePath.ImgPath: string;
begin
  Result := AppPath + 'imgs\';
end;

class function TFilePath.PngPath: string;
begin
  Result := AppPath + 'png\';
end;

end.

3. 新建uObj.pas单元

unit uObj;

interface

uses
  Classes, SyncObjs, SysUtils;

type
  //基类
  TObjBase = class(TPersistent)
  private
    FCS: TCriticalSection;
    procedure Lock;
    procedure Unlock;
  public
    procedure Clear; virtual; abstract;
    constructor Create; virtual;
    destructor Destroy; override;
  end;

  //员工
  TEmployeeClass= class of TEmployeeItem;

  TEmployeeItem= class(TCollectionItem)
  private
    fName: string;
    fSex: string;
    fImg: string;
  published
    property _Name: string read fName write fName;
    property _Sex: string read fSex write fSex;
    property _Img: string read fImg write fImg;
  public
    procedure Assign(item: TEmployeeItem); reintroduce;
  end;

  TEmployeeItems= class(TOwnedCollection)
  private
    function getItem(index: integer): TEmployeeItem;
    procedure setItem(index: Integer; const item: TEmployeeItem);
  public
    property Items[index: integer]: TEmployeeItem read getItem write setItem; default;
    function Add: TEmployeeItem;
    procedure Delete(index: integer);
    function Owner: TPersistent;
    destructor Destroy; override;
  end;

  TEmployees= class(TObjBase)
  private
    FEmployeeItems: TEmployeeItems;
    function getCount: Integer;
  protected
    function getEmployeeItemClass: TEmployeeClass;
  public
    constructor Create; override;
    destructor Destroy; override;
    procedure Clear; override;

    property Count: Integer read getCount;
    property Items: TEmployeeItems read FEmployeeItems;
    function LoadFromList(sList: TStringList; var sErr: string): Boolean;
  end;

implementation

{ TO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值