From Clomosy Docs

No edit summary
No edit summary
Line 3: Line 3:
</div>
</div>


<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.<br>
<span style="color:blue"><b>AComponent</b></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.<br>


<span style="color:blue"> xName</span> : The name of the defined listview should be written.<br>
<span style="color:blue"><b>xName</b></span> : The name of the defined listview should be written.<br>


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>
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>
Line 113: Line 113:


<pre>
<pre>
procedure SetupSqlConnection;
void SetupSqlConnection;
begin
{
Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
end;
}
</pre>
</pre>


Line 124: Line 124:
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>


Line 147: Line 151:
[[File:TableQuery.png|550px|frameless]]<br><br>
[[File:TableQuery.png|550px|frameless]]<br><br>


'''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 Example#Scanning Barcode with ListView SearchBox |Scanning Barcode with ListView SearchBox]] 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>


== Sql Server Example ==
<b> Example Code:</b><br>
 
<pre>
:'''TRObject Syntax'''
Var   
 
  MyForm:TclForm;
  Var   
  testListview : TClListView;
    MyForm:TclForm;
    testListview : TClListView;
void onItemClicked;
 
{
  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;
  }
 
:'''Base Syntax'''
  Var 
  MyForm:TclForm;
  testListview : TClListView;
 
  procedure 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>
 
<div class="alert alert-secondary" role="alert" data-bs-theme="light">
Below is the same example implemented on an SQLite database.
</div>


: <span style="color:blue"> Below is the same example implemented on an SQLite database. </span>
<h2>Example 3: Usage of SQLite</h2><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>
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 360: Line 320:
== SqLite Example ==
== SqLite Example ==


:'''TRObject Syntax'''
<pre>
<pre>


Line 456: Line 415:
</pre>
</pre>


:'''Base Syntax'''
<b>Output:</b><br>
<pre>
[[File:ListView.png|450px|frameless]]<br>
  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>
 
'''Output:'''<br>


[[File:ListView.png|450px|frameless]]
<h2> See Also </h2>
* [[Components]]
* [[Object Properties]]
* [[AddNewEvent]]

Revision as of 12:47, 7 November 2024

AComponent : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.

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 Scanning Barcode with ListView SearchBox 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);
    }
  }


SqLite Example


  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