procedure TForm1.LinkToControl(Control: TControl; DataSet: TUniQuery; FieldName:
string);
var
DataName:
string;
BindSourceDB: TBindSourceDB;
BindingsList: TBindingsList;
LinkListControl: TLinkListControlToField;
LinkControl: TLinkControlToField;
begin
DataName := DataSet.
Name;
if (DataName = '
')
and Assigned(DataSet.DataSource)
then
DataName := DataSet.DataSource.
Name;
if Assigned(Control.FindComponent(DataName + '
_BindSource'))
then
raise Exception.CreateFmt('
LinkToControl: %s.%s ist bereits an %s (%s) gebunden.', [DataName, FieldName, Control.
Name, Control.ClassName]);
BindSourceDB := TBindSourceDB.Create(Control);
BindSourceDB.
Name := DataName + '
_BindSource';
BindSourceDB.DataSet := DataSet;
BindSourceDB.DataSet.Active := True;
BindSourceDB.DataSource.Enabled := True;
BindingsList := TBindingsList.Create(BindSourceDB);
BindingsList.
Name := DataName + '
_BindingsList';
if Control
is TCombobox
then
Begin
LinkListControl := TLinkListControlToField.Create(BindingsList);
LinkListControl.
Name := DataName + '
_LinkListControl';
LinkListControl.Control := Control;
LinkListControl.DataSource := BindSourceDB;
LinkListControl.FieldName := FieldName;
LinkListControl.Active := True;
end
else
Begin
LinkControl := TLinkControlToField.Create(BindingsList);
LinkControl.
Name := DataName + '
_LinkListControl';
LinkControl.Control := Control;
LinkControl.DataSource := BindSourceDB;
LinkControl.FieldName := FieldName;
LinkControl.Active := True;
End;
end;