lue.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 的知识。这是一个非常完美和强劲的动态约束
程序示例:我们只需要在服务器端修改相关业务而无须修
改客户程序,也无须发布新的客户
程序。
通过以下步骤建立客户端程序:
拖一个 DCOMConnection 元件
设置: RemoteServer=ConstraintSvr.Constraints
拖一个 ClientDataset 元件
设置: RemoteServer=DCOMConnection1
设置: ProviderName=prvCustomer
拖一个 DataSource
设置: DataSet=ClientDataset1
拖一个 DBNavigator
设置: DataSource=DataSource1
拖一个 Button
设置: Name=btnOpen
双击 button 建立 click 事件,btnOpenClick 事件代码如下:
procedure TFormConstraintClient.BtnOpenClick(Sender: TObject);
begin
if ClientDataSet1.Active then
ClientDataSet1.Close;
ClientDataSet1.Open; { Refresh the dataset }
BtnOpen.Caption := ''&Reopen'';
end;