unit FormMain;
interface
uses
{Winapi.} Windows,
{Winapi.} Messages,
{System.} SysUtils,
{System.} Variants,
{System.} Classes,
{System.} Contnrs,
{Vcl.} Graphics,
{Vcl.} Controls,
{Vcl.} Forms,
{Vcl.} Dialogs,
{Vcl.} StdCtrls,
{Vcl.} ComCtrls,
DataListContainer;
type
TForm1 =
class( TForm )
ListView1 : TListView;
Button1 : TButton;
Button2 : TButton;
Label1 : TLabel;
procedure Button1Click( Sender : TObject );
procedure Button2Click( Sender : TObject );
private
FPersons : TObjectList;
FAddresses : TObjectList;
FPersonsPresenter : TDataListContainer;
FAddressPresenter : TDataListContainer;
procedure ShowInfo( AStart, AStop : TDateTime; ACount : Integer );
public
procedure AfterConstruction;
override;
procedure BeforeDestruction;
override;
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
uses
{System.} DateUtils,
DataListToListView,
Person, Address;
{ TForm1 }
procedure TForm1.AfterConstruction;
var
LIdx : Integer;
begin
inherited;
// Musterdaten erstellen
FPersons := TObjectList.Create( True );
for LIdx := 1
to 3000
do
begin
FPersons.Add( TPerson.Create( '
Lustig, Peter', EncodeDate( 1975, 1, 1 ) ) );
FPersons.Add( TPerson.Create( '
Traurig, Walter', EncodeDate( 1975, 2, 1 ) ) );
FPersons.Add( TPerson.Create( '
Mustermann, Erika', EncodeDate( 1975, 3, 1 ) ) );
end;
// Definition der Spalten
FPersonsPresenter := TDataListContainer.Create;
FPersonsPresenter.AddColumn( '
Name', '
Fullname', 150 );
FPersonsPresenter.AddColumn( '
Geburtstag', '
DOB', 80 );
FPersonsPresenter.DataList := FPersons;
// Musterdaten erstellen
FAddresses := TObjectList.Create( True );
for LIdx := 1
to 2500
do
begin
FAddresses.Add( TAddress.Create( '
Am Walde 23', 12345, '
Hinterm Berg' ) );
FAddresses.Add( TAddress.Create( '
Im Weiher 12', 23456, '
Vordem Berg' ) );
FAddresses.Add( TAddress.Create( '
Auf der Hecke 5', 34567, '
Beidem Berg' ) );
FAddresses.Add( TAddress.Create( '
Nebenstollen 5', 45678, '
Unterm Berg' ) );
end;
// Definition der Spalten
FAddressPresenter := TDataListContainer.Create;
FAddressPresenter.AddColumn( '
Straße', '
Street', 150 );
FAddressPresenter.AddColumn( '
PLZ', '
ZipCode', 80 );
FAddressPresenter.AddColumn( '
Ort', '
City', 80 );
FAddressPresenter.DataList := FAddresses;
end;
procedure TForm1.BeforeDestruction;
begin
inherited;
FPersonsPresenter.Free;
FPersons.Free;
FAddressPresenter.Free;
FAddresses.Free;
end;
procedure TForm1.Button1Click( Sender : TObject );
var
LStart, LStop : TDateTime;
begin
LStart := Now;
PresentData( ListView1, FPersonsPresenter );
LStop := Now;
ShowInfo( LStart, LStop, FPersonsPresenter.DataList.Count );
end;
procedure TForm1.Button2Click( Sender : TObject );
var
LStart, LStop : TDateTime;
begin
LStart := Now;
PresentData( ListView1, FAddressPresenter );
LStop := Now;
ShowInfo( LStart, LStop, FAddressPresenter.DataList.Count );
end;
procedure TForm1.ShowInfo( AStart, AStop : TDateTime; ACount : Integer );
begin
Label1.Caption := Format( '
%d Einträge in %dms', [ACount, MilliSecondsBetween( AStop, AStart )] );
end;
end.