Search code examples
delphidelphi-11-alexandriatms-web-core

How can I load data into the TWebTableControl in TMS WEB Core?


I have a TWebTableControl that I need to load data into, but I do not understand how to do this.

Delphi Form Designer

I do not understand the documentation either: https://download.tmssoftware.com/doc/tmswebcore/components/twebtablecontrol/

It says to use TableControl.Cells[col,row]: string;, but how?

My table's name is tblCoupons. I have no idea how to load data into this table. Can anyone help with a code example or guide, please?


Solution

  • Here's a code example to put data into the TWebTableControl:

    var
      I: UInt64;
    begin
      TableControl.ColCount := 4;
      TableControl.RowCount := 1;
    
      TableControl.Cells[0,0] := 'First Column Heading';
      TableControl.Cells[1,0] := 'Second Column Heading';
      TableControl.Cells[2,0] := 'Third Column Heading';
      TableControl.Cells[3,0] := 'Fourth Column Heading';
    
      For I := 1 to 10 do
      begin
        TableControl.RowCount := TableControl.RowCount + 1;
    
        TableControl.Cells[0,I] := 'Random Data col_1 for Row ' + I.ToString;
        TableControl.Cells[1,I] := 'Random Data col_2 for Row ' + I.ToString;
        TableControl.Cells[2,I] := 'Random Data col_3 for Row ' + I.ToString;
        TableControl.Cells[3,I] := 'Random Data col_4 for Row ' + I.ToString;
      end;
    end;
    

    TableControl being the name of your table component.

    This is what the above code will generate in a default TWebTableControl component:

    TWebTableControl in TMS WEB Core populated using Delphi Programming Code