unit FormMain;
interface
uses
SysUtils,
Forms,
StdCtrls,
Controls,
Classes;
type
TDataItem =
record
Name :
string;
Value :
string;
end;
TMainForm =
class( TForm )
ComboBox1 : TComboBox;
Edit1 : TEdit;
Edit2 : TEdit;
Edit3 : TEdit;
Edit4 : TEdit;
Edit5 : TEdit;
Edit6 : TEdit;
Edit7 : TEdit;
Edit8 : TEdit;
SelectedValue_Label : TLabel;
procedure ControlChange( Sender : TObject );
// OnChange-Event der Controls hiermit verbinden
procedure FormShow( Sender : TObject );
private
FModelLoading : Boolean;
FCurrent : Integer;
FData :
array [0 .. 7]
of TDataItem;
procedure DoLoadFromModel;
procedure DoSaveToModel;
procedure LoadFromModel;
procedure SaveToModel;
procedure SyncWithModel;
public
procedure AfterConstruction;
override;
end;
var
MainForm : TMainForm;
implementation
{$R *.dfm}
{ TMainForm }
procedure TMainForm.AfterConstruction;
var
LIdx : Integer;
begin
inherited;
// Daten vorbereiten
for LIdx := Low( FData )
to High( FData )
do
FData[LIdx].
Name := '
Item ' + IntToStr( LIdx + 1 );
end;
procedure TMainForm.ControlChange( Sender : TObject );
begin
SyncWithModel;
end;
procedure TMainForm.DoLoadFromModel;
var
LIdx : Integer;
begin
// Combobox mit Werten füllen
ComboBox1.Items.BeginUpdate;
try
ComboBox1.Items.Clear;
for LIdx := Low( FData )
to High( FData )
do
ComboBox1.Items.Add( FData[LIdx].
Name );
finally
ComboBox1.Items.EndUpdate;
end;
ComboBox1.ItemIndex := FCurrent;
// Wert der aktuellen Auswahl
if FCurrent < 0
then
SelectedValue_Label.Caption := '
'
else
SelectedValue_Label.Caption := FData[FCurrent].Value;
// Edit-Felder füllen
Edit1.Text := FData[0].Value;
Edit2.Text := FData[1].Value;
Edit3.Text := FData[2].Value;
Edit4.Text := FData[3].Value;
Edit5.Text := FData[4].Value;
Edit6.Text := FData[5].Value;
Edit7.Text := FData[6].Value;
Edit8.Text := FData[7].Value;
end;
procedure TMainForm.DoSaveToModel;
begin
// Auswahl der ComboBox
FCurrent := ComboBox1.ItemIndex;
// Inhalt der Edit-Felder
FData[0].Value := Edit1.Text;
FData[1].Value := Edit2.Text;
FData[2].Value := Edit3.Text;
FData[3].Value := Edit4.Text;
FData[4].Value := Edit5.Text;
FData[5].Value := Edit6.Text;
FData[6].Value := Edit7.Text;
FData[7].Value := Edit8.Text;
end;
procedure TMainForm.FormShow( Sender : TObject );
begin
LoadFromModel;
end;
procedure TMainForm.LoadFromModel;
begin
if FModelLoading
then
Exit;
FModelLoading := True;
try
DoLoadFromModel;
finally
FModelLoading := False;
end;
end;
procedure TMainForm.SaveToModel;
begin
if FModelLoading
then
Exit;
DoSaveToModel;
end;
procedure TMainForm.SyncWithModel;
begin
SaveToModel;
LoadFromModel;
end;
end.