unit DSFake;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Contnrs, ComCtrls;
type
TFakeField =
class
private
FValue:
string;
function GetAsString:
string;
public
property Value:
string read FValue
write FValue;
property AsString:
string read GetAsString;
end;
TFakeDataset =
class
private
FIndex: integer;
FNames,
FFirstnames,
FDaysOfBirth: TObjectList;
function GetEOF: Boolean;
public
constructor Create;
destructor Destroy;
override;
procedure Open;
procedure Close;
procedure Next;
procedure First;
function FieldByName(
const Fieldname:
string): TFakeField;
property EOF: Boolean
read GetEOF;
end;
TfrmMain =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
FDataset: TFakeDataset;
FListview: TListView;
public
{ Public-Deklarationen }
property Dataset: TFakeDataset
read FDataset;
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
{ TFakeDataset }
procedure TFakeDataset.Close;
begin
//Brauch ma nich
end;
constructor TFakeDataset.Create;
var
aName, aFirstname, aBirthday: TFakeField;
begin
(* Wir tun mal so, als wäre das hier eine Ergebnismenge *)
FNames := TObjectList.Create;
FFirstNames := TObjectList.Create;
FDaysOfBirth := TObjectList.Create;
aName := TFakeField.Create;
aFirstname := TFakeField.Create;
aBirthday := TFakeField.Create;
aName.Value := '
Korn';
aFirstname.Value := '
Klara';
aBirthday.Value := '
12.12.1912';
FNames.Add(aName);
FFirstnames.Add(aFirstname);
FDaysOfBirth.Add(aBirthday);
aName := TFakeField.Create;
aFirstname := TFakeField.Create;
aBirthday := TFakeField.Create;
aName.Value := '
Cron';
aFirstname.Value := '
Maria';
aBirthday.Value := '
01.12.1924';
FNames.Add(aName);
FFirstnames.Add(aFirstname);
FDaysOfBirth.Add(aBirthday);
aName := TFakeField.Create;
aFirstname := TFakeField.Create;
aBirthday := TFakeField.Create;
aName.Value := '
Beam';
aFirstname.Value := '
Jim';
aBirthday.Value := '
12.10.1899';
FNames.Add(aName);
FFirstnames.Add(aFirstname);
FDaysOfBirth.Add(aBirthday);
aName := TFakeField.Create;
aFirstname := TFakeField.Create;
aBirthday := TFakeField.Create;
aName.Value := '
Fiddich';
aFirstname.Value := '
Glen';
aBirthday.Value := '
02.10.1990';
FNames.Add(aName);
FFirstnames.Add(aFirstname);
FDaysOfBirth.Add(aBirthday);
end;
destructor TFakeDataset.Destroy;
begin
FNames.Free;
FFirstNames.Free;
FDaysOfBirth.Free;
inherited;
end;
procedure TFakeDataset.First;
begin
FIndex := 0;
end;
function TFakeDataset.GetEOF: Boolean;
begin
Result := FIndex >= FNames.Count;
end;
function TFakeDataset.FieldByName(
const Fieldname:
string): TFakeField;
begin
if AnsiSameText(Fieldname, '
Name')
then
Result := TFakeField(FNames[FIndex])
else if AnsiSameText(Fieldname, '
FirstName')
then
Result := TFakeField(FFirstNames[FIndex])
else if AnsiSameText(Fieldname, '
DayOfBirth')
then
Result := TFakeField(FDaysOfBirth[FIndex])
else
Result :=
nil;
end;
procedure TFakeDataset.Next;
begin
inc(FIndex);
end;
procedure TFakeDataset.Open;
begin
First;
end;
{ TFakeField }
function TFakeField.GetAsString:
string;
begin
Result := FValue;
end;
(* Ende Fake, Anfang Simulation *)
procedure TfrmMain.FormCreate(Sender: TObject);
var
Item: TListItem;
Column: TListColumn;
begin
FListview := TListview.Create(self);
FListview.Parent := self;
FListview.Align := alClient;
FListview.ViewStyle := vsReport;
Column := FListView.Columns.Add;
Column.Caption := '
Name';
Column.Width := 120;
Column := FListView.Columns.Add;
Column.Caption := '
Vorname';
Column.Width := 120;
Column := FListView.Columns.Add;
Column.Caption := '
Geburtsdatum';
Column.Width := 120;
FDataset := TFakeDataset.Create;
(* So sähe das in etwa auch bei einem "normalen" Dataset aus *)
Dataset.Open;
while not Dataset.EOF
do
begin
Item := FListview.Items.Add;
Item.Caption := Dataset.FieldByName('
Name').AsString;
Item.SubItems.Add(Dataset.FieldByName('
Firstname').AsString);
Item.SubItems.Add(Dataset.FieldByName('
DayOfBirth').AsString);
Dataset.Next;
end;
Dataset.Close;
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
Dataset.Free;
end;
end.