模块的 Provider 命名。代码如下:
{ Copyright (c) 1999 - 2000 by John Kaster, Dan Miser and Louis Kleiman }
procedure GetProviderList( ProviderList : TStrings );
var
ProviderNames : OLEVariant;
I : Integer;
DataSet : TDataSet;
GenObject : TComponent;
begin
if (Screen.DataModuleCount = 0) then
Raise Exception.Create( ''No data modules are active.'' );
ProviderList.Clear;
{ Get the list of all providers for the first data module.
All instances of the data module are probably the same. }
ProviderNames := IConstraints(TConstraints(Screen.DataModules[0])).
AS_GetProviderNames;
for I := VarArrayLowBound(ProviderNames, 1) to
VarArrayHighBound(ProviderNames, 1) do
begin
{ Retrieve the component matching the provider name }
GenObject := Screen.DataModules[0].FindComponent(ProviderNames[I]);
if (GenObject is TDataSetProvider) then
DataSet := TDataSetProvider(Screen.DataModules[0].
FindComponent(ProviderNames[I])).DataSet
else if (GenObject is TDBDataSet) then
DataSet := TDataSet(Screen.DataModules[0].
FindComponent(ProviderNames[I]))
else
DataSet := nil;
{ Add it to the list of providers, attaching the Dataset if assigned }
ProviderList.AddObject(ProviderNames[I], DataSet);
end; { for }
end; { GetProviderList() }
接收约束内容
现在从RDM的实例获取 provider 列表,其他的都是一些传统的 Delphi 代码。通过一个列表框元件来显示
Provider ,通过另一个列表框元件来显示每个提供者的栏位约束值。 Provider列表框元件命名为lbProviders
。代码如下:
procedure TFormConstraintsEditor.lbProvidersClick(Sender: TObject);
var
DataSet : TDataSet;
I : Integer;
SaveActive : Boolean;
begin
lbFields.Clear;
DataSet := TDataSet(lbProviders.Items.Objects[lbProviders.ItemIndex]);
if Assigned(DataSet) then
begin
SaveActive := DataSet.Active;
DataSet.Open;
try
for I := 0 to DataSet.FieldCount - 1 do
lbFields.Items.AddObject(DataSet.Fields[I].FieldName,
DataSet.Fields[I]);
finally
DataSet.Active := SaveActive;
end; { tryfinally }
end; { if }
end;
编辑约束内容值
现在使用编辑元件来为所选的栏位赋值。拖放这些控件到表单上,然后在下面的click 事件中将相应的选
取的栏位的约束属性值赋值给编辑元件。 字段栏位列表框元件命名为lbFields 。代码如下:
procedure TFormConstraintsEditor.lbFieldsClick(Sender: TObject);
var
Field : TField;
begin
Field := TField(lbFields.Items.Objects[lbFields.ItemIndex]);
if Assigned(Field) then
begin
edErrorMessage.Text := Field.ConstraintErrorMessage;
edCustomConstraint.Text := Field.CustomConstraint;
edDisplayLabel.Text := Field.DisplayLabel;
edEditMask.Text := Field.EditMask;
edDisplayFormat.Text := '''';
edMinValue.Text := '''';
edMaxValue.Text := '''';
cbVisible.Checked := Field.Visible;
if Field is TNumericField then
begin
with Field as TNumericField do
edDisplayFormat.Text := DisplayFormat;
if Field is TFloatField then
with Field as TFloatField do
begin
edMinValue.Text := FloatToStr( MinValue );
edMaxValue.Text := FloatToStr( MaxValue );
end
else if Field is TBCDField then
with Field as TBCDField do
begin
edMinValue.Text := FloatToStr( MinValue );
edMaxValue.Text := FloatToStr( MaxValue );
end
else if Field is TIntegerField then
with Field as TIntegerField do
begin
edMinVa