SmartBinding achieve DataSet and bind the ListView and synchronized display

kbmMW 5.10.10 released, this release resolves issues I raised when the DataSet add or delete records, ListView can simultaneously display. Let's look at specific implementation code.

In order to solve the above problems, the author is IkbmMWBindingNavigator interface adds the following method:

  IkbmMWBindingNavigator = interface
     ......
     function Delete:boolean;
     function Insert:boolean; overload;
     function Insert(const ANames:array of string; const AValues:array of TValue):boolean; overload;
     function Append:boolean; overload;
     function Append(const ANames:array of string; const AValues:array of TValue):boolean; overload;

     procedure Refresh;

     property Value[const AName:string]:TValue read GetValue write SetValue;
  end;

By the above method, the data set can be realized to add, delete and other operations.

Next, look at the specific implementation process:

The first step, with the ListView and bind the DataSet get the interface IkbmMWBinding returned. By property Navigator IkbmMWBinding interface, you can access IkbmMWBindingNavigator interfaces to invoke the new method above.

procedure TForm1.Button9Click(Sender: TObject);
begin

  bnd:=nil;
  Binding.Clear;
  //ListView1.Items.Clear;

  dataset:=mt;

  bnd:=Binding.Bind(dataset,'f1',Edit1,'Text',[mwboTwoWay]);
       Binding.Bind(dataset,'f2',Edit2,'Text',[mwboTwoWay]);
       Binding.Bind(dataset,'f3',DateEdit1,'Date',[mwboTwoWay]);

  bnd:= Binding.Bind(dataset,'f1',ListView1,'#Text1');
        Binding.Bind(dataset,'f2',ListView1,'#Text2');
        Binding.Bind(dataset,'f3',ListView1,'#Text3');

  Binding.Bind(dataset,'@',ListView1,'@',[mwboTwoWay]);

end;

When this code is executed, it will appear the following results:

 

 ListView correct display all records content data set. Whether we perform dataset.Next or bnd.Navigator.Next, ListView and dataSet location will be visible on the current record.

The second step, to achieve deleted

Now we delete a record:

procedure TForm1.Button12Click(Sender: TObject);
begin
//  mt.Delete;
//  bnd.Navigator.Refresh;

   bnd.Navigator.Delete;

end;

If the direct operation data set, the method performed Delete, then you need to perform bnd.Navigator.Refresh;

If the Delete method performed directly bnd, Refresh method need not be performed.

The third step, the added

procedure TForm1.Button11Click(Sender: TObject);
begin
//  mt.Append;
//  mt.FieldByName('f1').Value:='101';
//  mt.FieldByName('f2').Value:=101;
//  mt.Post;
//
//  bnd.Navigator.Refresh;

    bnd.Navigator.Append;
    bnd.Navigator.Value['f1']:='101';
    bnd.Navigator.Value['f2']:=101;
    bnd.Navigator.Value['f3']:=Date;

end;

The above code, the same operation as delete, the data set can be achieved, it may be realized by bnd interface. When implemented through the data set, call the Refresh method.

The last point is the experience to exit the current interface to process the bnd interfaces:

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
    bnd:=nil;
    Binding.Clear;
end;

 

Guess you like

Origin www.cnblogs.com/kinglandsoft/p/11942385.html