TwwDataGrid - Getting Started - How to set colcount and rowcount?

982 views
Skip to first unread message

gregc...@gmail.com

unread,
Jan 23, 2014, 2:24:08 PM1/23/14
to woll2woll...@googlegroups.com
I have just dropped the TwwDataGrid onto my Form and I am wanting to set the number of columns and the number of rows but the Object Inspector does not display these properties.  I am wanting to display a variety of glyphs into the cells and then use touch gestures to reveal the underlying data.
 

Roy Woll

unread,
Jan 23, 2014, 4:54:07 PM1/23/14
to woll2woll...@googlegroups.com

Hi Greg,

Using the TwwDataGrid without a physical database

If you want your grid bound to data in-memory instead of a physical file or database, then there are a number of ways you can achieve this with the TwwDataGrid. This completely frees you from having to create a physical file . 

One way to go about this is to use the native control TClientDataSet (included with Delphi) as an in-memory dataset, and then link it to the InfoPower grid. You can define its structure, add fields, and add data, all without using any physical file. It also requires very little effort to setup. The advantages become enormous once you have done this, as you can then filter your dataset, search for records, sort, etc. all without having to write the code for this functionality. TClientDataSet also is supported on all Delphi FireMonkey platforms, including the mobile space (Android and iOS). 

Or, attach this code to create an in-memory dataset, add records, and display its contents. You can attach our grid to such a in-memory dataset. You can also do this at design time or with code as the steps below indicates. 

The following summarizes the steps in using a TClientDataSet for an in-memory manager of records. 

1. Create a TClientDataset instance. You may do it in design-time (simply drop a component on form) or at run-time (for example, in the OnCreate event of your form): 

var InMemoryDataSet: TClientDataSet;
begin
  InMemoryDataSet := TClientDataset.Create(Application);

2. Now add field definitions (FieldDefs property) using the IDE designer or with code such as the following.  

  InMemoryDataSet.FieldDefs.Add('ID', ftInteger, 0, False);
  InMemoryDataSet.FieldDefs.Add('Status', ftString, 10, False);
  InMemoryDataSet.FieldDefs.Add('Created', ftDate, 0, False);
  InMemoryDataSet.FieldDefs.Add('Volume', ftFloat, 0, False);

 

3. Create the dataset in the IDE by right-clicking the component or use code like the following. 

  InMemoryDataSet.CreateDataset

 

4. Open the dataset 

  InMemoryDataSet.Active:= true;

5. You're done. Now you can use the TDataSet methods to manipulate your in-memory data. You can add, edit, or delete records using the TDataset methods. You can filter using the Filter property, sort using the IndexFieldName property, search using the Locate method, etc. 

For example, to add random values to records: 

  for i := 1 to 100 do
  begin
    InMemoryDataSet.Append;
    InMemoryDataSet.FieldByName('ID').AsInteger := i;
    InMemoryDataSet.FieldByName('Status').AsString := 'Code'+IntToStr(i);
    InMemoryDataSet.FieldByName('Created').AsDateTime := Date();
    InMemoryDataSet.FieldByName('Volume').AsFloat := Random(10000);
    InMemoryDataSet.Post;
  end;

 

Once you have successfully created this in-memory dataset, you can view it using the TwwDataGrid. Just create a TBindSource pointing to InMemoryDataSet, and set the TwwDataGrid.DataSource property to the TBindSource

Example

The following code attached to a button, creates a TClientDataSet at runtime and adds 5 records with each record containing the columns 'StringField' and 'IntegerField'  

uses Datasnap.DBClient;

procedure TForm45.Button1Click(Sender: TObject);
var
  i: integer;
begin
  with TClientDataset.Create(nil) do
    try
      Close;

      // Add fields
      FieldDefs.Add('StringField', ftString, 10);
      FieldDefs.Add('IntegerField', ftInteger);

      CreateDataset;

      // Add records
      for i := 1 to 5 do
      begin
        AppendRecord([IntToStr(i), i]);
        { or
          Insert;
          FieldByName('StringField').AsString := IntToStr(i);
          FieldByName('IntegerField').AsInteger := i;
          Post;
        }
      end;
      First;
      while not EOF do
      begin
        ShowMessage(FieldByName('StringField').AsString);
        next;
      end;
    finally
      free;
    end;
end;

-Roy

Greg Cromack

unread,
Jan 23, 2014, 6:44:01 PM1/23/14
to woll2woll...@googlegroups.com
So by defining a ClientDataSet containing TGraphicFields then I can achieve my grid with glyphs?  As I understand it - gestures are available on all platforms.  Is that right?

Roy Woll

unread,
Jan 23, 2014, 7:19:12 PM1/23/14
to woll2woll...@googlegroups.com
>So by defining a ClientDataSet containing TGraphicFields then I can achieve my grid with glyphs?  As I understand it 

Exactly. 

Gestures should be available on non-windows platforms as well.

-Roy

Greg Cromack

unread,
Jan 24, 2014, 10:03:47 PM1/24/14
to woll2woll...@googlegroups.com
So the DataSource property of the TwwDataGrid needs to point to a TBindSource BUT there is no such component on the XE5 Tool Palette.  There is a TBindSourceDB and a TBindSourceDBX.  Is this TBindSource needed even if the DataSet is not limited to "in memory"?  If I am using a MyDAC component can I point the TwwDataGrid directly to its TMyTable or TMyQuery?

Greg Cromack

unread,
Jan 24, 2014, 10:26:13 PM1/24/14
to woll2woll...@googlegroups.com
I have tried to use the TwwDataGrid with a TBindSourceDB and a TMyTable but the TwwDataGrid remains in its empty state.

Roy Woll

unread,
Jan 25, 2014, 2:41:55 PM1/25/14
to woll2woll...@googlegroups.com
Greg,

The last steps I outlined were for an in-memory dataset. It sounds like your most recent question was about a physical database (MySQL). In any case, 
have you performed the steps I outlined in the original email? You do not have to drop a TBindSourceDB component into your app, as Delphi automatically does this for you when you right click on the dataset, and then select the menu choice Create TBindSource.


DataSource: Assign this property to associate the grid with a TBindSource 
With the FireMonkey TwwDataGrid component you will need to associate it with a TBindSourceDB component. This can easily be done by dropping in a TBindSourceDB component and assigning its Dataset property, or you can right-click your dataset at design time and click on the Create TBindSource menu option. 

Once you have attached the datasource, you can dbl-click the grid at design time and select the columns and their properties.  

The steps are the same as when using the native delphi control TGrid, so you might want to test out your setup with just native components first. Once you have done this successfully, its simply a matter of assigning your datasource property of the TwwDataGrid.

Greg Cromack

unread,
Jan 29, 2014, 5:14:49 PM1/29/14
to woll2woll...@googlegroups.com
Roy

Unfortunately when I cut-and-pasted your code into a test project - I had undefined variables because I did not have the appropriate USE units.  

I have tried again using advice from your latest post and I have managed to get the grid populated with simple fields from a ClientDataSet.

What I am trying to do is get "up to speed" with how to actually use TwwDataGrid but in the absence of "getting started" documentation, I am limited to experimenting.  

Even though TwwDataGrid can hold graphic fields - I simply lack the experience to achieve this goal.  I have tried the following:

  ReservationsStatusCDS.FileName := TPath.GetDocumentsPath + PathDelim + 'guestmanagercentralxml' + PathDelim + 'ReservationsStatus.xml';
  if FileExists(ReservationsStatusCDS.FileName) then DeleteFile(ReservationsStatusCDS.FileName);
  with ReservationsStatusCDS do
  begin
    with FieldDefs.AddFieldDef do
    begin
      Name := 'Reservation';
      DataType := ftGraphic;
      Required := True;
    end;
    CreateDataSet;
    LogChanges := False;
    Append;
    (FieldByName('Reservation') As TBlobField).LoadFromFile('blueoblong.bmp');
    Post;
    Close;
  end;
  BindSourceDB1.DataSet := ReservationsStatusCDS;

BUT even though the TwwDataGrid has a DataSource of BindSourceDB1 - it remains empty.  

I am sure the fault lies with me BUT without documentation I cannot get this grid to do what it can do (and I want it to do).


Greg

Roy Woll

unread,
Jan 29, 2014, 11:45:35 PM1/29/14
to woll2woll...@googlegroups.com
Hi Greg,

I have made a short video demonstrating how to get the InfoPower FM Grid tied to an unbound datasource using a TClientDataSet.


Hope this helps.

-Roy

Greg Cromack

unread,
Jan 30, 2014, 5:05:28 PM1/30/14
to woll2woll...@googlegroups.com
Thanks Roy that was a great "getting started" video.  I also eagerly await your response to "Delphi XE5 - Images in TwwDBGrid".  Maybe another video?

Woll2Woll Software

unread,
Jan 30, 2014, 8:16:00 PM1/30/14
to woll2woll...@googlegroups.com
Hi Greg,

"Delphi XE5 - Images in TwwDBGrid"

That message was about our InfoPower VCL components. It has nothing to do with InfoPower FM.

To add an image, just repeat the steps in the video, but define a column type of ftGraphic. The grid will default ftGraphic to an image type.  Of course in the beginning you would have no images, so you won't see any graphics. If you want to load an image at runtime by clicking on the cell, set the column's ControlAttributes.Image.EnableOpenDialog to true.

-Roy

Greg Cromack

unread,
Jan 30, 2014, 9:20:01 PM1/30/14
to woll2woll...@googlegroups.com
Hi Roy

It is the "set the column's ControlAttributes.Image.EnableOpenDialog to true." that I am having trouble with.  The Object Inspector does not allow me to open up the (TwwGridColumns).  It is the loading a glyph from a PNG file at runtime that I am trying to implement BUT how do I access a cell's contents?

Greg Cromack

unread,
Feb 5, 2014, 2:54:11 PM2/5/14
to woll2woll...@googlegroups.com
Hi Roy

As I have found in the past with other Grid components - their applicability outside of displaying conventional data fields from a dataset is limited.

My search for a flexible Grid component that will enable me to handle my glyphs - continues.

Thanks for your help in understanding the basics of your Infopower FM grid.

Greg

Roy Woll

unread,
Feb 5, 2014, 5:57:55 PM2/5/14
to woll2woll...@googlegroups.com
I thought I responded to your earlier post, but I don't see my reply. Perhaps I closed my browser instead of posting.

In any case to all you should have to do is to dbl-click the grid to customize the columns. You could also right-click the grid to edit the columns and define the graphic. In any case, if you have defined a ftgraphic datatype, and have created a dataset it will automatically assume you want to use a TImage control to display the graphic. To load images, you only need to load the tfield. Were you able to dbl-click the grid to bring up the columns editor as we did in the video I posted?

-Roy


Greg Cromack

unread,
Feb 8, 2014, 4:22:52 PM2/8/14
to woll2woll...@googlegroups.com
Yes - at last I have my glyph in my InfoPower grid.  

I am interested in Marcus' "Painting Images in TwwDataGrid" - "as it seems something lots of folks would want to do" (to quote Embarcadero Support).  

So if in future - you are preparing documentation, videos, etc for InfoPower Grid could you please prepare something for us graphics users?

This "Getting Started" question is now closed.

Thanks Roy.

Reply all
Reply to author
Forward
0 new messages