procedure TForm14.LinkToControl(Control: TControl; DataSet: TDataSet; FieldName:
string);
var
DataName:
string;
BindSourceDB: TBindSourceDB;
BindingsList: TBindingsList;
LinkListControl: TLinkListControlToField;
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;
// das Beides hat hier doch eigentlich nichts zu suchen
BindSourceDB.DataSource.Enabled := True;
//
BindingsList := TBindingsList.Create(BindSourceDB);
BindingsList.
Name := DataName + '
_BindingsList';
LinkListControl := TLinkListControlToField.Create(BindingsList);
LinkListControl.
Name := DataName + '
_LinkListControl';
LinkListControl.Control := Control;
LinkListControl.DataSource := BindSourceDB;
LinkListControl.FieldName := FieldName;
LinkListControl.Active := True;
end;