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

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

被折叠的 条评论
为什么被折叠?



