的可靠性 MIDAS 2、3 数据包能够自动的由 AppServer 到客户端传递以下数据栏位属性: Constraint PRoperty Description ---------------------------------------------------------------------------------------------- ConstraintErrorMessage Message to display if data for the field if not valid. Example: CustNo cannot be blank CustomConstraint Constraints to place on the validation of the field. Expressions can be used for this constraint. Example: CustNo IS NOT NULL DisplayFormat Controls formatting of the field for display DisplayLabel Used as the data field's default column heading. Example: Customer # EditMask Used for customizing data entry for the field. Example: 0000 MaxValue The maximum value of a numeric field MinValue The minimum value of a numeric field Visible A boolean value indicating whether the field should be visible in a grid by default 实现约束编辑服务器(Constraint Editor Server)
只要客户连接到 MIDAS Server ,相关RDM(remote data module)就会自动创建并提供给客户来访问Server 约束编辑服务器(ConstraintSvr.exe)在第一次使用这些RDM时会去获取 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() }
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; { try...finally } end; { if } end;
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 edMinValue.Text := IntToStr( MinValue ); edMaxValue.Text := IntToStr( MaxValue ); end else if Field is TLargeIntField then with Field as TLargeIntField do begin edMinValue.Text := IntToStr( MinValue ); edMaxValue.Text := IntToStr( MaxValue ); end; end else if Field is TDateTimeField then with Field as TDateTimeField do edDisplayFormat.Text := DisplayFormat; end; { if } end;
提交已编辑的约束值
在给字段栏位约束赋给了相应的值后,需提交应用这些约束值。代码如下:
procedure TFormConstraintsEditor.actApplyExecute(Sender: TObject); var Field : TField; begin Field := TField(lbFields.Items.Objects[lbFields.ItemIndex]); if Assigned(Field) then begin Field.ConstraintErrorMessage := edErrorMessage.Text; Field.CustomConstraint := edCustomConstraint.Text; Field.DisplayLabel := edDisplayLabel.Text; Field.EditMask := edEditMask.Text; Field.Visible := cbVisible.Checked; if Field is TNumericField then begin with Field as TNumericField do DisplayFormat := edDisplayFormat.Text; if Field is TFloatField then with Field as TFloatField do begin MinValue := StrToInt( edMinValue.Text ); MaxValue := StrToInt( edMaxValue.Text ); end else if Field is TBCDField then with Field as TBCDField do begin MinValue := StrToInt( edMinValue.Text ); MaxValue := StrToInt( edMaxValue.Text ); end else if Field is TIntegerField then with Field as TIntegerField do begin MinValue := StrToInt( edMinValue.Text ); MaxValue := StrToInt( edMaxValue.Text ); end else if Field is TLargeIntField then with Field as TLargeIntField do begin MinValue := StrToInt( edMinValue.Text ); MaxValue := StrToInt( edMaxValue.Text ); end; end else if Field is TDateTimeField then with Field as TDateTimeField do DisplayFormat := edDisplayFormat.Text; end; { if } end;
现已创建了 ConstraintSvr 的主要代码,详细代码可以下载。
创建强制约束的客户程序
客户程序比创建服务器程序简单多拉,因为他只需要简单的接收一个修改后的数据包,而无须有编写
Server 的知识。这是一个非常完美和强劲的动态约束程序示例:我们只需要在服务器端修改相关业务而无须修