1. 创建一个Window application 应用,添加组件。(如下图)
(1) ControlList 控件(显示列表数据)
(2) ClientDataSet 控件(连接本地数据)
(3) 放置 image1,(显示图片) 2个label (显示列表数据)
2.编写代码:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Data.DB,
Datasnap.DBClient, Vcl.ControlList;
type
TForm2 = class(TForm)
ControlList1: TControlList;
fish: TClientDataSet;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
fishSpeciesNo: TFloatField;
fishCategory: TStringField;
fishCommon_Name: TStringField;
fishSpeciesName: TStringField;
fishLengthcm: TFloatField;
fishLength_In: TFloatField;
fishNotes: TMemoField;
fishGraphic: TGraphicField;
procedure ControlList1BeforeDrawItem(AIndex: Integer; ACanvas: TCanvas;
ARect: TRect; AState: TOwnerDrawState);
procedure fishAfterOpen(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.ControlList1BeforeDrawItem(AIndex: Integer; ACanvas: TCanvas;
ARect: TRect; AState: TOwnerDrawState);
begin
fish.RecNo:=AIndex+1;
label1.Caption:=fishcommon_name.asstring;
label2.Caption:=fishnotes.AsString;
var ms:=tmemorystream.Create;
fishgraphic.SaveToStream(ms);
ms.Position:=8;
image1.Picture.LoadFromStream(ms);
ms.Free;
end;
procedure TForm2.fishAfterOpen(DataSet: TDataSet);
begin
controllist1.ItemCount:=fish.RecordCount;
end;
end.
3.运行效果: