Jump to content
FranzB

livebindings without livebindings designer , code only

Recommended Posts

we will  execute  the opposite  of the instructions given here http://docwiki.embarcadero.com/RADStudio/Sydney/en/LiveBindings_in_RAD_Studio ,  

create a livebindings  application  , show a query in a stringgrid,  without using  the live bindings designer 

 

my code  goes like this ,  the issue  :  the code compiles, I guess open query  also  is functional but the stringgrid remains empty 

 

var
  BindSourceDB1: TBindSourceDB;
  LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource;
begin
  aServername := edt_Servername.Text;

  adatabasename := edt_databasename.Text;

  ConnecttoDatabase(aServername, adatabasename, aConnection); //   a subfunction

  aQuery.SQL.Text := 'select  * from  MyTable ';

  aQuery.Open; //  guess fine, because on a VCL application the  data are displayed 

  BindSourceDB1 := TBindSourceDB.Create(Self);
  BindSourceDB1.DataSet := aQuery;


 
  LinkGridToDataSourceBindSourceDB1 := TLinkGridToDataSource.Create(Self);
  LinkGridToDataSourceBindSourceDB1.DataSource := BindSourceDB1;
  LinkGridToDataSourceBindSourceDB1.GridControl := strngrd_Objecttable;

end;

 

Edited by FranzB

Share this post


Link to post

Yes FluentLiveBindings should work, and so easy to write 

BindingsList1.BindGrid(Grid1).ToBindSource(BindSourceDB1);

But no CustomFormat can be used (perhaps I don't know how, or further development ?)

My code for runtime linking

var ABindGrid : TBindGridLink;
begin
 ABindGrid:=TBindGridLink.Create(self);
 ABindGrid.ControlComponent := Grid1;
 ABindGrid.SourceComponent := BindSourceDB1;

// synch
 with ABindGrid.PosControlExpressions.AddExpression do
       begin
          ControlExpression := 'Selected';
          SourceExpression := 'Math_Max(0,DBUtils_ActiveRecord(Self))';
        end;

 with ABindGrid.PosSourceExpressions.AddExpression do
        begin
          ControlExpression := 'Math_Max(1,Selected+1)';
          SourceExpression := 'DBUtils_ValidRecNo(Self)';
        end;

// columns
 with ABindGrid.ColumnExpressions.AddExpression do
        begin
          ColumnName := 'Column1';
          ColumnIndex := 0;
          SourceMemberName := 'SS_NUMBER';             // field format '0 000 000 00' (a crazy one ;-) just for test)   
          with FormatCellExpressions.AddExpression do
            begin
              ControlExpression := 'Data';
              SourceExpression := 'DisplayText';  // I kept Display text, but 10.4.1 don't need  
            end;
        end;

 with ABindGrid.ColumnExpressions.AddExpression do
        begin
          ColumnName := 'Column2';
          ColumnIndex := 1;
          SourceMemberName := 'FIRST_NAME';
          With FormatCellExpressions.AddExpression do
            begin
              ControlExpression := 'Data';
              SourceExpression := 'Value+'#39' '#39'+Dataset.LAST_NAME.text';
            end;
        end;

Regret, I am unable to use a "with TBindGridLink.Create(Self) do ...." form  

Edited by Serge_G

Share this post


Link to post

i  like  to  use  https://github.com/malcolmgroves/FluentLiveBindings

 

var
 
  BindSourceDB1: TBindSourceDB;
 
begin
  aServername := edt_Servername.Text;

  adatabasename := edt_databasename.Text;

  ConnecttoDatabase(aServername, adatabasename, aConnection);

  aQuery.SQL.Text := 'select  * from  Mytab';

  aQuery.Active := True;


 BindSourceDB1 := TBindSourceDB.Create(Self);
  BindSourceDB1.DataSet := aQuery;


  BindingsList1.BindGrid(grd_objecttab).ToBindSource(BindSourceDB1);

 

 

but run time error msg is now  like  below , 

any idea  for this error ? 

 

 

error_live_bindings.png

Edited by FranzB

Share this post


Link to post

Well, :classic_dry: , I only test Fluent Livebindings with a TGrid, not TStringGrid, but demo included in the package is with a stringgrid, so I don't see anything except a missing unit in your form.

My tests are somewhere a little not objectives in the way I put on the same form a grid linked (TBindGridLink) with the visual livebindings editor and another with Fluent (raising the fact this last is not a WYWSSEWYG method) unit so all the units were added. 

 

Share this post


Link to post

A little late, but for others with the same problem...

 

I found (one of the possible)  causes :
In the uses clause Fmx.Bind.Grid was missing.
No errors if it's not there, just not working (!)

kind regards

Dirk Janssens.

Edited by Dirk Janssens

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×