的可靠性 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 的知識。這是一個非常完美和強勁的動態約束程序示例:我們只需要在服務器端修改相關業務而無須修