Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Displaying database data in a FireMonkey application

Discussion in 'Delphi Programming' started by AdminDF, Mar 12, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    This is the start of an in-depth series on the new LiveBindings technology found in Delphi XE2-XE5. At its most basic level LiveBindings is the mechanism provided for FireMonkey applications to display and edit data from a database on screen, a job that in the VCL is traditionally done with data-aware controls. FireMonkey however has no data-aware controls, instead LiveBindings allow you to bind database fields to standard controls.

    There is much more to LiveBindings, but for today we’ll look at this most simplest of use cases, displaying and editing a database table in a FireMonkey application.

    Firstly we need to create a new FireMonkey HD Application by selecting

    File
    New
    FireMonkey HD Application

    [​IMG]

    Now we need a database for our application to access. Drop a TClientDataSet (or any other TDataSet descendent) and a TDataSource on the form just as you would in a VCL application.

    [​IMG]

    Connect the TDataSource to the TClientDataSet by it’s DataSet property, exactly as you do with a VCL application.

    [​IMG]

    If you used a TClientDataSet you’ll need to specify an XML data file for it to load. I’m using the biolife.xml file from the Delphi XE2 samples directory.

    [​IMG]

    Now we start placing components on the form. Start with a TStringGrid.

    Note that it isn’t TDBGrid or any other TDB style of component.

    [​IMG]

    Next drop onto the form one of each of these standard controls

    TLabel
    TEdit
    TMemo

    [​IMG]

    Your form should now resemble this.

    [​IMG]

    Now we need to start binding these standard controls to the database fields.

    Drop a TBindingsList anywhere onto your form.


    [​IMG]

    Follow it with a TBindScopeDB, also anywhere on your form.

    [​IMG]

    Now we link the binding engine to the database engine by the DataSource property of the TBindScopeDB.

    [​IMG]

    With the TLabel selected, in the Object Inspector select


    LiveBindings
    Dropdown arrow
    Link to DB Field

    [​IMG]

    Select the field you wish to display in this label control. In this example I’m displaying the Common_Name field.

    [​IMG]

    Repeat this process for the TEdit control. In the Object Inspector select


    LiveBindings
    Dropdown arrow
    Link to DB Field,

    [​IMG]

    and select the field for the TEdit to display/edit.

    [​IMG]

    A TMemo is bound the same way, selecting “Link to DB Field” from the LiveBindings property in the Object inspector
    [​IMG]

    and then selecting a BLOB field from the field list.

    In the biolife.xml file this is the Notes field.


    [​IMG]

    Binding a TStringGrid is slightly different. In the object inspector

    LiveBindings
    Dropdown arrow
    Link to DB DataSource

    [​IMG]

    Rather than selecting an individual field for a grid we select the parent TBindScopeDB.

    [​IMG]

    Lastly the TClientDataSet needs to be opened when the application runs.

    [​IMG]

    You can now run the application and edit the TClientDataSet data from within the standard non data-aware controls.

    [​IMG]
     
  2. DVi
    Offline

    DVi DF Junior

    RE:

    Perfect, thank you very much..
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block