From Clomosy Docs

No edit summary
No edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling. Besides, you use this component when you want to pull data from the database.<br>
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function AddNewListView(AComponent: TCLComponent; xName: string): TclListView;
</div>


AddNewListView (TComponent, xName): TclListView
<span style="color:blue"><b>AComponent</b></span> : Specifies the parent of the object to be defined.<br>


<span style="color:blue"> TComponent</span> : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.
<span style="color:blue"><b>xName</b></span> : The name of the defined listview should be written.<br>


<span style="color:blue"> xName</span> : The name of the defined listview should be written.
Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling. Besides, you use this component when you want to pull data from the database.<br>


<div class="alert alert-ligth border border-3 border-warning rounded-5 p-4 shadow-sm" role="alert">
When an object of the TclListView class is created, fields are generated within this object. Assignments are made according to these field names. The following fields are included.<br>
<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Listview Fields  !!style="background-color: #c3d7e0"| Explanation
|-
| <b>MAIN_TEXT</b> || It is the main area. This place is in bold and is in the middle left.
|-
| <b>SUB_TEXT</b> || It is located just below "MAIN_TEXT".
|-
| <b>SIDE_TEXT_TOP</b> || It is located in the upper right corner.
|-
| <b>SIDE_TEXT_CENTER</b> || It is located in the middle right corner.
|-
| <b>SIDE_TEXT_BOTTOM</b> || It is located in the lower right corner.
|-
| <b>FOOTER_TEXT</b> || It is located in the lower left corner.
|-
| <b>RECORD_GUID</b> || (Unique field) product ids are written here.
|}
</div>
</div>


<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"|Definition  
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition  
|-
|-
|TClListView || Listview1 : TClListView;  || A variable belonging to the TClListView class is created.
|TClListView || Listview1 : TClListView;  || A variable belonging to the TClListView class is created.
|-
|-
|AddNewListView || Listview1 = MyForm.AddNewListView(Form1,'testListview'); || A new TClListView component is added to the form.
|AddNewListView || Listview1 = Form1.AddNewListView(Form1,'Listview1'); || A new TClListView component is added to the form.
|-
|-
|Width || Listview1.Width = 150; ||Allows adjusting the width of the image.
|Width || Listview1.Width = 150; ||Allows adjusting the width of the image.
Line 23: Line 49:
|Margins ||Listview1.Margins.Left = 50; // Right, Top, Bottom ||With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.<br>[[File:TclListViewMargins.png|frameless|200px]]
|Margins ||Listview1.Margins.Left = 50; // Right, Top, Bottom ||With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.<br>[[File:TclListViewMargins.png|frameless|200px]]
|-
|-
|clSelectedItemData ||testListview.clSelectedItemData('MAIN_TEXT'); || It is used to get information about the data clicked when the ListView is clicked. (You can call it with a procedure and use it in the desired field.)
|clSelectedItemData ||Listview1.clSelectedItemData('MAIN_TEXT'); || It is used to get information about the data clicked when the ListView is clicked. (You can call it with a procedure and use it in the desired field.)
Instead of "MAIN_TEXT", you can call whatever location you have added data to in the ListView. Other parameters you can call below;<br>
Instead of "MAIN_TEXT", you can call whatever location you have added data to in the ListView. Other parameters you can call below;<br>
*SUB_TEXT
*SUB_TEXT
Line 38: Line 64:
|CheckedCount||Listview1.Items.CheckedCount(true) || Returns the number of items selected in the ListView.
|CheckedCount||Listview1.Items.CheckedCount(true) || Returns the number of items selected in the ListView.
|}
|}
</div>
<h2>Example 1: Selecting, Processing, and Displaying Items in a ListView</h2><br>
It creates a TClListView and a TClButton component on a form. The TClListView contains items loaded from JSON data and is made selectable with CheckBoxes. When the Button is clicked, the MAIN_TEXT values of the selected (Checked) items are retrieved and displayed both as plain text and separated by a ; character. Additionally, the number of selected items in the ListView is shown on the screen. This operation aims to provide the user with information about the selected items.<br>
<pre>
Var 
  MyForm:TclForm;
  ListView1 : TClListView;
  Button1 : TclButton;
  stringList : TclStringList;
void onItemClicked;
{
  stringList = ListView1.GetValueCheckBoxList('MAIN_TEXT'); // It retrieves the MAIN_TEXT of items with Checked set to True in ListView1.
  ShowMessage(stringList.text);
  ShowMessage(stringList.DelimitedText); // It separates the selected data with a ';' character.
  ShowMessage(IntToStr(ListView1.Items.CheckedCount(true)));  // It returns the CheckedCount within the ListView.
}
void CreateListView;
{
  ListView1 = MyForm.AddNewListView(MyForm,'ListView1');
  ListView1.Align = alClient;
  ListView1.clLoadListViewDataFromDataset(Clomosy.ClDataSetFromJSON('[
  {"RECORD_GUID":"AAAAAA","MAIN_TEXT":"Hello World","SUB_TEXT":5,"SIDE_TEXT_TOP":1,"SIDE_TEXT_CENTER":1,"SIDE_TEXT_BOTTOM":1,"FOOTER_TEXT":1},
  {"RECORD_GUID":"BBBBBB","MAIN_TEXT":"Hi World","SUB_TEXT":1,"SIDE_TEXT_TOP":1,"SIDE_TEXT_CENTER":1,"SIDE_TEXT_BOTTOM":1,"FOOTER_TEXT":1}]'));
  ListView1.CheckedProperty = True; //It must be enabled if a CheckBox is to be used within the ListView.
}
{
  MyForm = TclForm.Create(Self);
  Button1 = MyForm.AddNewButton(MyForm,'Button1','Click');
  Button1.StyledSettings = ssFamily;
  Button1.TextSettings.Font.Size = 20;
  Button1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');
  MyForm.AddNewEvent(Button1,tbeOnClick,'onItemClicked');
  CreateListView;
 
  MyForm.Run;
}
</pre>
<h2>Example 2: Usage of Sql Server</h2><br>
<div class="alert alert-warning" role="alert" data-bs-theme="light">
After defining objects for the TclListView class, a database connection will be established. Here, an MSSQL database is used.
</div>
<pre>
void SetupSqlConnection;
{
Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
}
</pre>




: <span style="color:blue">After making the definition, we will create the database connection. MSSQL database is used here.</span>
<blockquote style="background-color:#F7F5EB">
procedure SetupSqlConnection;<br>
begin<br>
  Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);<br>
end;<br>
</blockquote>
So let's take a look at where they got this database information from.<br>
So let's take a look at where they got this database information from.<br>
[[File:DatabaseConnect.png|center|650px|thumb|none]]<br>
[[File:DatabaseConnect.png|center|650px|thumb|none]]<br>
You have learned your server name. You will have created your username and password while downloading sql. You make a connection entry with the information you created in the institution and write them in the code.<br>
You have learned your server name. You will have created your username and password while downloading sql. You make a connection entry with the information you created in the institution and write them in the code.<br>
Now the last thing to do is to write your database name. For this, we create a database. Follow the steps below for creation.<br>
Now the last thing to do is to write your database name. For this, we create a database. Follow the steps below for creation.<br>
[[File:DatabaseCreating.png|center|650px|thumb|none]]
[[File:DatabaseCreating.png|center|650px|thumb|none]]<br>


Now that we have completed the database operations, we will add the data to the ListView.<br>
Now that we have completed the database operations, we will add the data to the ListView.<br>
For this, a new query is created and the "Clomosy.DBSQLServerConnection" connection is cloned.<br>
For this, a new query is created and the "Clomosy.DBSQLServerConnection" connection is cloned.<br>
<blockquote style="background-color:#F7F5EB">
<pre>
Var<br>
Var
   foodListQuery : TClSqlQuery;<br>
   foodListQuery : TClSqlQuery;
begin<br>
{
   foodListQuery := TClSqlQuery.Create(nil);<br>
   foodListQuery = TClSqlQuery.Create(nil);
   foodListQuery.Connection := Clomosy.DBSQLServerConnection;
   foodListQuery.Connection = Clomosy.DBSQLServerConnection;
</blockquote>
}
</pre>
 
The sql query sentence to be executed in the query is defined.<br>
The sql query sentence to be executed in the query is defined.<br>
<blockquote style="background-color:#F7F5EB">
 
foodListQuery.SQL.Text := 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';
<pre>
</blockquote>
foodListQuery.SQL.Text = 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';
</pre>
 
In order to define the above code, you must create a table in your database and add data to it. In this example we have added products. The product has a name and price.<br><br>
In order to define the above code, you must create a table in your database and add data to it. In this example we have added products. The product has a name and price.<br><br>
[[File:TableDisplay.png|550px|frameless]]<br><br>
[[File:TableDisplay.png|550px|frameless]]<br><br>
Then we write our code above to our database. As below, the names of the columns in the database have been changed. We didn't change the database columns here, we just did the cloning.<br><br>
 
To display the database field names in the TclListView object, the field names must be modified according to the list name.<br><br>
 
[[File:TableQuery.png|550px|frameless]]<br><br>
[[File:TableQuery.png|550px|frameless]]<br><br>
So why did we change the columns this way? Could we write something else instead?<br>
The reason we change it this way is ListView fields. Even though they are not actually visible on the screen, we can add data to positions such as write the information we get from a database into the Listview to the right, write to the left. Where else can we write on this screen, their names are available in the table below. From here, you can position your data in the area you want.<br>
{| class="wikitable"
! Listview Fields !! Explanation
|-
| '''MAIN_TEXT''' || It is the main area. This place is in bold and is in the middle left.
|-
|'''SUB_TEXT''' || It is located just below "MAIN_TEXT".
|-
| '''SIDE_TEXT_TOP''' || It is located in the upper right corner.
|-
| '''SIDE_TEXT_CENTER''' || It is located in the middle right corner.
|-
| '''SIDE_TEXT_BOTTOM''' || It is located in the lower right corner.
|-
| '''FOOTER_TEXT''' || It is located in the lower left corner.
|-
| '''RECORD_GUID''' || (Unique field) product ids are written here.
|}


'''View:'''<br>
<b>Appearance:</b><br>
[[File:TclListViewFields.png|frameless|600px]]<br><br>
[[File:TclListViewFields.png|frameless|600px]]<br><br>


The query is run.<br>
The query is run.<br>
<blockquote style="background-color:#F7F5EB">
<pre>
foodListQuery.Open;
foodListQuery.Open;
</blockquote>
</pre>
 
If there is a record after the query is run, the relevant record is added to the list.<br>
If there is a record after the query is run, the relevant record is added to the list.<br>
<blockquote style="background-color:#F7F5EB">
<pre>
if foodListQuery.Found then<br>
if (foodListQuery.Found)
  begin<br>
{
    testListview.clLoadListViewDataFromDataset(foodListQuery);<br>
testListview.clLoadListViewDataFromDataset(foodListQuery);
  end;
}
</blockquote>
</pre>
 
Query is closed and freed.
Query is closed and freed.
<blockquote style="background-color:#F7F5EB">
<pre>
foodListQuery.Close;<br>
foodListQuery.Close;
foodListQuery.Free;
foodListQuery.Free;
</blockquote>
</pre>
Now the application is complete. As soon as the ListView component was defined, the search box could come up automatically. Now we will add a button to search by scanning the barcode on this search bar. For this, we will initially define the variable "TSearchBox" to access the search bar inside the ListView and then write the required code to access it.<br>


<blockquote style="background-color:#F7F5EB">
Now the application is complete. As soon as the ListView component was defined, the search box could come up automatically. Now we will add a button to search by scanning the barcode on this search bar. For this, we will initially define the variable "TclSearchBox" to access the search bar inside the ListView and then write the required code to access it.<br>
'''Var'''<br>
<pre>
testSearchBox : '''TSearchBox''';
Var
</blockquote>
SearchBox1 : TclSearchBox;
</pre>


<blockquote style="background-color:#F7F5EB">
<pre>
testSearchBox := testListview.'''GetSearchBox''';
SearchBox1 = testListview.GetSearchBox;
</blockquote>
</pre>
We now have access to the searchBox. You can add a button to it and read the barcode with "CallBarcodeReader" and add it to the search bar. Let's look at the [[Code Example#Scanning Barcode with ListView SearchBox |Scanning Barcode with ListView SearchBox]] page for an example application.


We now have access to the searchBox. You can add a button to it and read the barcode with "CallBarcodeReader" and add it to the search bar.<br>
Let's look at the [[Code Examples |SQLite Database - Searching via Barcode Scanning from the List]] page for an example application.


To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:<br>
To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:<br>
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.<br>


'''Example:'''<br>
<b> Example Code:</b><br>  
:'''Base Syntax'''
<pre>
  Var   
Var   
  MyForm:TclForm;
  MyForm:TclForm;
  testListview : TClListView;
  testListview : TClListView;
 
  procedure onItemClicked;
void onItemClicked;
  begin
{
   ShowMessage(testListview.clSelectedItemData('MAIN_TEXT'));
   ShowMessage(testListview.clSelectedItemData('MAIN_TEXT'));
  end;
}
  procedure SetupSqlConnection;
void SetupSqlConnection;
  begin
{
    Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',1433);
  Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',1433);
  end;
}
 
  procedure CreateListView;
void CreateListView;
  begin
{
    testListview := MyForm.AddNewListView(MyForm,'testListview');
  testListview = MyForm.AddNewListView(MyForm,'testListview');
    testListview.Align := alClient;
  testListview.Align = alClient;
    MyForm.AddNewEvent(testListview,tbeOnItemClick,'onItemClicked');
  MyForm.AddNewEvent(testListview,tbeOnItemClick,'onItemClicked');
  end;
}
 
  procedure AddDataToListview;
void AddDataToListview;
  Var
Var
    foodListQuery : TClSqlQuery;
  foodListQuery : TClSqlQuery;
  begin
{
    foodListQuery := TClSqlQuery.Create(nil);
  foodListQuery = TClSqlQuery.Create(nil);
    try
  try
      foodListQuery.Connection := Clomosy.DBSQLServerConnection;
    foodListQuery.Connection = Clomosy.DBSQLServerConnection;
      foodListQuery.SQL.Text := 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';
    foodListQuery.SQL.Text = 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';
      foodListQuery.Open;
    foodListQuery.Open;
      if foodListQuery.Found then
    if (foodListQuery.Found)
      begin
    {
        testListview.clLoadListViewDataFromDataset(foodListQuery);
      testListview.clLoadListViewDataFromDataset(foodListQuery);
      end;
    }
    finally
  finally
      foodListQuery.Close;
    foodListQuery.Close;
      foodListQuery.Free;
    foodListQuery.Free;
    end;
  }
  end;
}
 
  begin
{
   MyForm := TclForm.Create(Self);
   MyForm = TclForm.Create(Self);
 
 
   CreateListView;
   CreateListView;
   SetupSqlConnection;
   SetupSqlConnection;
   AddDataToListview;
   AddDataToListview;
   MyForm.Run;
   MyForm.Run;
   
}
  end;
</pre>


:'''TRObject Syntax'''
<div class="alert alert-secondary" role="alert" data-bs-theme="light">
Below is the same example implemented on an SQLite database.
</div>


  Var 
<h2>Example 3: Usage of SQLite</h2><br>
    MyForm:TclForm;
    testListview : TClListView;
 
  void onItemClicked;
  {
    ShowMessage(testListview.clSelectedItemData('MAIN_TEXT'));
  }
  void SetupSqlConnection;
  {
    Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',1433);
  }
 
  void CreateListView;
  {
    testListview = MyForm.AddNewListView(MyForm,'testListview');
    testListview.Align = alClient;
    MyForm.AddNewEvent(testListview,tbeOnItemClick,'onItemClicked');
  }
 
  void AddDataToListview;
  Var
    foodListQuery : TClSqlQuery;
  {
    foodListQuery = TClSqlQuery.Create(nil);
    try
      foodListQuery.Connection = Clomosy.DBSQLServerConnection;
      foodListQuery.SQL.Text = 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';
      foodListQuery.Open;
      if (foodListQuery.Found)
      {
        testListview.clLoadListViewDataFromDataset(foodListQuery);
      }
    finally
      foodListQuery.Close;
      foodListQuery.Free;
    }
  }
 
  {
    MyForm = TclForm.Create(Self);
   
    CreateListView;
    SetupSqlConnection;
    AddDataToListview;
    MyForm.Run;
  }
 
: <span style="color:blue"> Below is the same example implemented on an SQLite database. </span>


First, establish the database connection. To connect to the SQLite database, the DBSQLiteConnect function is used. If this function exists, it operates on it; otherwise, it adds a new database.<br>
First, establish the database connection. To connect to the SQLite database, the DBSQLiteConnect function is used. If this function exists, it operates on it; otherwise, it adds a new database.<br>
Line 299: Line 317:
</pre>
</pre>


 
<b> Example Code: </b><br>
'''SqLite Example:'''<br>
:'''Base Syntax'''
<pre>
  var
    MyForm : TclForm;
    ListView1 : TClListView;
    Qry : TClSQLiteQuery;
 
  procedure onItemClicked;
  begin
  ShowMessage(ListView1.clSelectedItemData('MAIN_TEXT'));
  end;
 
  procedure SqLiteInsertData;
  begin
    try
      Clomosy.DBSQLiteQuery.Sql.Text := '
    INSERT INTO Products (productId, productName, productPrice) VALUES (1, ''Iphone 11'', 18000.00);
    INSERT INTO Products (productId, productName, productPrice) VALUES (2, ''Xiaomi Redmi Note 11 Pro'', 15000.50);
    INSERT INTO Products (productId, productName, productPrice) VALUES (3, ''Omix X600'', 20000.75);
    INSERT INTO Products (productId, productName, productPrice) VALUES (4, ''Huawei Nova Y70'', 25000.00);
    INSERT INTO Products (productId, productName, productPrice) VALUES (5, ''Samsung Galaxy S20'', 30000.25);
    INSERT INTO Products (productId, productName, productPrice) VALUES (6, ''Iphone 14 Pro Max'', 50000.25);';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
     
      ShowMessage('Adding data to the table was successful!');
    except
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    end;
  end;
 
  procedure SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  begin
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text := 'SELECT name FROM sqlite_master WHERE type="table" AND name="Products";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
     
      // Check the results
      TableExists := not Clomosy.DBSQLiteQuery.Eof;
     
      // Create the table if it does not exist
      if not TableExists then
      begin
        Clomosy.DBSQLiteQuery.Sql.Text := 'CREATE TABLE Products(productId INTEGER NOT NULL,
        productName TEXT NOT NULL,
        productPrice DECIMAL(18, 0) NOT NULL,
        PRIMARY KEY (productId))';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
       
        ShowMessage('Table successfully added to the database!');
        SqLiteInsertData;
      end else
      begin
        ShowMessage('The Products table already exists.');
      end;
 
    except
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    end;
  end;
 
  procedure GetData;
  begin
    try
      Qry := Clomosy.DBSQLiteQueryWith('SELECT productId as RECORD_GUID, productName as MAIN_TEXT, productPrice as SIDE_TEXT_BOTTOM FROM Products');
      Qry.OpenOrExecute;
      ListView1.clLoadListViewDataFromDataset(Qry);
   
    except
      ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
    end;
  end;
  procedure CreateListView;
  begin
    ListView1 := MyForm.AddNewListView(MyForm,'ListView1');
    ListView1.Align := alClient;
    MyForm.AddNewEvent(ListView1,tbeOnItemClick,'onItemClicked');
   
  end;
 
  begin
   
    MyForm := TclForm.Create(Self);
    CreateListView;
    SqLiteConnectionCreateTable;
    GetData;
   
    MyForm.Run;
  end;
</pre>
 
 
:'''TRObject Syntax'''
<pre>
<pre>


Line 493: Line 413:
</pre>
</pre>


'''Output:'''<br>
<b>Output:</b><br>
[[File:ListView.png|450px|frameless]]<br>


[[File:ListView.png|450px|frameless]]
<h2> See Also </h2>
* [[Components]]
* [[Object Properties]]
* [[AddNewEvent]]
{{#seo:|title=TclListView Using in Clomosy - Clomosy Docs}}
{{#seo:|description=Discover TclListView in Clomosy, a component for displaying and managing items in lists, with fields, selection, and database integration support.}}

Latest revision as of 14:25, 24 December 2024

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined listview should be written.

Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling. Besides, you use this component when you want to pull data from the database.

Feature Use of Definition
TClListView Listview1 : TClListView; A variable belonging to the TClListView class is created.
AddNewListView Listview1 = Form1.AddNewListView(Form1,'Listview1'); A new TClListView component is added to the form.
Width Listview1.Width = 150; Allows adjusting the width of the image.
Height Listview1.Height = 50; Allows adjusting the height of the image.
Align Listview1.Align = alTop; With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the page to learn about these features.
Margins Listview1.Margins.Left = 50; // Right, Top, Bottom With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
TclListViewMargins.png
clSelectedItemData Listview1.clSelectedItemData('MAIN_TEXT'); It is used to get information about the data clicked when the ListView is clicked. (You can call it with a procedure and use it in the desired field.)

Instead of "MAIN_TEXT", you can call whatever location you have added data to in the ListView. Other parameters you can call below;

  • SUB_TEXT
  • SIDE_TEXT_TOP
  • SIDE_TEXT_CENTER
  • SIDE_TEXT_BOTTOM
  • FOOTER_TEXT
  • RECORD_GUID
CheckedProperty Listview1.CheckedProperty = True; It is an expression used to determine or set whether the items in the TclListView component are checked.
GetValueCheckBoxList stringValue = Listview1.GetValueCheckBoxList('MAIN_TEXT'); It retrieves the value of the specified field for the selected items in ListView1. In the example, it will retrieve the data in the MAIN_TEXT field of the selected item.
CheckedCount Listview1.Items.CheckedCount(true) Returns the number of items selected in the ListView.

Example 1: Selecting, Processing, and Displaying Items in a ListView


It creates a TClListView and a TClButton component on a form. The TClListView contains items loaded from JSON data and is made selectable with CheckBoxes. When the Button is clicked, the MAIN_TEXT values of the selected (Checked) items are retrieved and displayed both as plain text and separated by a ; character. Additionally, the number of selected items in the ListView is shown on the screen. This operation aims to provide the user with information about the selected items.

Var   
  MyForm:TclForm;
  ListView1 : TClListView;
  Button1 : TclButton;
  stringList : TclStringList;
void onItemClicked;
{
  stringList = ListView1.GetValueCheckBoxList('MAIN_TEXT'); // It retrieves the MAIN_TEXT of items with Checked set to True in ListView1.
  ShowMessage(stringList.text);
  ShowMessage(stringList.DelimitedText); // It separates the selected data with a ';' character.
  ShowMessage(IntToStr(ListView1.Items.CheckedCount(true)));  // It returns the CheckedCount within the ListView.
}
void CreateListView;
{
  ListView1 = MyForm.AddNewListView(MyForm,'ListView1');
  ListView1.Align = alClient;
  ListView1.clLoadListViewDataFromDataset(Clomosy.ClDataSetFromJSON('[
  {"RECORD_GUID":"AAAAAA","MAIN_TEXT":"Hello World","SUB_TEXT":5,"SIDE_TEXT_TOP":1,"SIDE_TEXT_CENTER":1,"SIDE_TEXT_BOTTOM":1,"FOOTER_TEXT":1},
  {"RECORD_GUID":"BBBBBB","MAIN_TEXT":"Hi World","SUB_TEXT":1,"SIDE_TEXT_TOP":1,"SIDE_TEXT_CENTER":1,"SIDE_TEXT_BOTTOM":1,"FOOTER_TEXT":1}]'));
  ListView1.CheckedProperty = True; //It must be enabled if a CheckBox is to be used within the ListView.
}

{
  MyForm = TclForm.Create(Self);
  Button1 = MyForm.AddNewButton(MyForm,'Button1','Click');
  Button1.StyledSettings = ssFamily;
  Button1.TextSettings.Font.Size = 20;
  Button1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');
  MyForm.AddNewEvent(Button1,tbeOnClick,'onItemClicked');
  CreateListView;
  
  MyForm.Run;
}

Example 2: Usage of Sql Server


void SetupSqlConnection;
{
Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
}


So let's take a look at where they got this database information from.

DatabaseConnect.png


You have learned your server name. You will have created your username and password while downloading sql. You make a connection entry with the information you created in the institution and write them in the code.
Now the last thing to do is to write your database name. For this, we create a database. Follow the steps below for creation.

DatabaseCreating.png


Now that we have completed the database operations, we will add the data to the ListView.
For this, a new query is created and the "Clomosy.DBSQLServerConnection" connection is cloned.

Var
  foodListQuery : TClSqlQuery;
{
  foodListQuery = TClSqlQuery.Create(nil);
  foodListQuery.Connection = Clomosy.DBSQLServerConnection;
}

The sql query sentence to be executed in the query is defined.

foodListQuery.SQL.Text = 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';

In order to define the above code, you must create a table in your database and add data to it. In this example we have added products. The product has a name and price.

TableDisplay.png

To display the database field names in the TclListView object, the field names must be modified according to the list name.

TableQuery.png

Appearance:
TclListViewFields.png

The query is run.

foodListQuery.Open;

If there is a record after the query is run, the relevant record is added to the list.

if (foodListQuery.Found)
{
testListview.clLoadListViewDataFromDataset(foodListQuery);
}

Query is closed and freed.

foodListQuery.Close;
foodListQuery.Free;

Now the application is complete. As soon as the ListView component was defined, the search box could come up automatically. Now we will add a button to search by scanning the barcode on this search bar. For this, we will initially define the variable "TclSearchBox" to access the search bar inside the ListView and then write the required code to access it.

Var
SearchBox1 : TclSearchBox;
SearchBox1 = testListview.GetSearchBox;

We now have access to the searchBox. You can add a button to it and read the barcode with "CallBarcodeReader" and add it to the search bar.
Let's look at the SQLite Database - Searching via Barcode Scanning from the List page for an example application.

To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.

Example Code:

 Var   
   MyForm:TclForm;
   testListview : TClListView;
 
 void onItemClicked;
 {
   ShowMessage(testListview.clSelectedItemData('MAIN_TEXT'));
 }
 void SetupSqlConnection;
 {
   Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',1433);
 }
 
 void CreateListView;
 {
   testListview = MyForm.AddNewListView(MyForm,'testListview');
   testListview.Align = alClient;
   MyForm.AddNewEvent(testListview,tbeOnItemClick,'onItemClicked');
 }
 
 void AddDataToListview;
 Var
   foodListQuery : TClSqlQuery;
 {
   foodListQuery = TClSqlQuery.Create(nil);
   try
     foodListQuery.Connection = Clomosy.DBSQLServerConnection;
     foodListQuery.SQL.Text = 'SELECT productId as RECORD_GUID, productName as MAIN_TEXT,productPrice as SIDE_TEXT_BOTTOM from Products';
     foodListQuery.Open;
     if (foodListQuery.Found)
     {
       testListview.clLoadListViewDataFromDataset(foodListQuery);
     }
   finally
     foodListQuery.Close;
     foodListQuery.Free;
   }
 }
 
 {
   MyForm = TclForm.Create(Self);
   
   CreateListView;
   SetupSqlConnection;
   AddDataToListview;
   MyForm.Run;
 }

Example 3: Usage of SQLite


First, establish the database connection. To connect to the SQLite database, the DBSQLiteConnect function is used. If this function exists, it operates on it; otherwise, it adds a new database.

  void SqLiteConnection;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', ''); 
    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }

After the database connection is established, if the desired table exists in the database, it will be listed. If it does not exist, the table will be created and data will be inserted.

  void SqLiteInsertData;
  {
    try
      Clomosy.DBSQLiteQuery.Sql.Text = '
    INSERT INTO Products (productId, productName, productPrice) VALUES (1, ''Iphone 11'', 18000.00);
    INSERT INTO Products (productId, productName, productPrice) VALUES (2, ''Xiaomi Redmi Note 11 Pro'', 15000.50);
    INSERT INTO Products (productId, productName, productPrice) VALUES (3, ''Omix X600'', 20000.75);
    INSERT INTO Products (productId, productName, productPrice) VALUES (4, ''Huawei Nova Y70'', 25000.00);
    INSERT INTO Products (productId, productName, productPrice) VALUES (5, ''Samsung Galaxy S20'', 30000.25);
    INSERT INTO Products (productId, productName, productPrice) VALUES (6, ''Iphone 14 Pro Max'', 50000.25);';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      ShowMessage('Adding data to the table was successful!');
    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
 
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Products";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      // Check the results
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
      
      // Create the table if it does not exist
      if not (TableExists)
      {
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE Products(productId INTEGER NOT NULL,
        productName TEXT NOT NULL,
        productPrice DECIMAL(18, 0) NOT NULL,
        PRIMARY KEY (productId))';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
        
        ShowMessage('Table successfully added to the database!');
        SqLiteInsertData;
      } else
      {
        ShowMessage('The Products table already exists.');
      }

    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }

Example Code:


  var
    MyForm : TclForm;
    ListView1 : TClListView;
    Qry : TClSQLiteQuery;
  
  void onItemClicked;
  {
   ShowMessage(ListView1.clSelectedItemData('MAIN_TEXT'));
  }
  
  void SqLiteInsertData;
  {
    try
      Clomosy.DBSQLiteQuery.Sql.Text = '
    INSERT INTO Products (productId, productName, productPrice) VALUES (1, ''Iphone 11'', 18000.00);
    INSERT INTO Products (productId, productName, productPrice) VALUES (2, ''Xiaomi Redmi Note 11 Pro'', 15000.50);
    INSERT INTO Products (productId, productName, productPrice) VALUES (3, ''Omix X600'', 20000.75);
    INSERT INTO Products (productId, productName, productPrice) VALUES (4, ''Huawei Nova Y70'', 25000.00);
    INSERT INTO Products (productId, productName, productPrice) VALUES (5, ''Samsung Galaxy S20'', 30000.25);
    INSERT INTO Products (productId, productName, productPrice) VALUES (6, ''Iphone 14 Pro Max'', 50000.25);';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      ShowMessage('Adding data to the table was successful!');
    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
 
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Products";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      // Check the results
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
      
      // Create the table if it does not exist
      if not (TableExists)
      {
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE Products(productId INTEGER NOT NULL,
        productName TEXT NOT NULL,
        productPrice DECIMAL(18, 0) NOT NULL,
        PRIMARY KEY (productId))';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
        
        ShowMessage('Table successfully added to the database!');
        SqLiteInsertData;
      } else
      {
        ShowMessage('The Products table already exists.');
      }

    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void GetData;
  {
    try
      Qry = Clomosy.DBSQLiteQueryWith('SELECT productId as RECORD_GUID, productName as MAIN_TEXT, productPrice as SIDE_TEXT_BOTTOM FROM Products');
      Qry.OpenOrExecute;
      ListView1.clLoadListViewDataFromDataset(Qry);
    
    except
      ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
    } 
  }
  void CreateListView;
  {
     ListView1 = MyForm.AddNewListView(MyForm,'ListView1');
     ListView1.Align = alClient;
     MyForm.AddNewEvent(ListView1,tbeOnItemClick,'onItemClicked');
     
  } 
  
  {
    
    MyForm = TclForm.Create(Self);
    CreateListView;
    SqLiteConnectionCreateTable;
    GetData;
    
    MyForm.Run;
  }

Output:
ListView.png

See Also