From Clomosy Docs

No edit summary
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Basis Guide is a customized guide for Clomosy. In the application, all the desired data can be accessed from the database. With the customized guide, it only returns data according to the searched request, without reaching all the data.<br>
It is a customized guide form. With the customized guide, it returns only the data that is queried without accessing all the data. In another use case, when data selected from a page search needs to be transferred to the previous page, the "TclGuideForm" component is used.<br>
In another use, the "TclGuideForm" component can be used when it is desired to transfer selected data from a page search to the previous page. Let's create a BasisGuide form now and continue the narrative over it. To create the form, it is necessary to define.<br>
MyGuideForm : TclGuideForm;


<pre style="background-color:#E14D2A; color:white"> When performing SQL operations, you must write your database information in the code section, otherwise the code will not work. </pre><br>
Before using these features, the form must be initialized.<br>
An object of the TclGuideForm class should be defined.<br>
<pre>
var
  GuideForm1 : TclGuideForm;
</pre>


Let's set up our connection to the sql database.<br>
The defined object must be created using the "Create" function.<br>
Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
<pre>
{
  GuideForm1 = TclGuideForm.Create(Self);
  GuideForm1.Run;
}
</pre>


After that, we need to add BasisGuide to reach the desired guide information. After that, we add a listView to the Guide form and connect it to our form.<br>
The features are provided in the table below.<br>
mainListviewGuide := TClListView(MyGuideForm.clFindComponent('FormClListView'));
 
mainListviewGuide.Align := alClient;
<div class="table-responsive">
mainListviewGuide.Visible := True;
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
|-
|ReturnItemData ||GuideForm1.ReturnItemData = 'MAIN_TEXT'; || The value of the desired field from the data clicked on in the list on the form page is retrieved and displayed in the next content. The name of the selected field must be written. In the example, the value from the "MAIN_TEXT" field is retrieved.
|-
|ReturnItemObject ||GuideForm1.ReturnItemObject = edtListNumber; || The value returned from the previously selected field is passed. In the example, the data has been transferred to a TclEdit component named "edtListNumber".
|}
</div>
<br>


After that, when we click on the button on the edit we wrote, it goes to the database and finds the value sought here and transfers it to the ListView.<br>
<b>Example</b><br>


'''Procedure OnGuideQryClick;'''
In this example, a TclForm will be created, containing a list view (TclListView), an interactive search field (TclProEdit), and a TclGuideForm to display data.<br>
  var
    clViewDataQuery :TclSQLQuery;
  begin
      clViewDataQuery:=TclSQLQuery.Create(Nil);
    Try
      clViewDataQuery.Connection := Clomosy.DBSQLServerConnection;
      clViewDataQuery.SQL.Text :='SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%');
      clViewDataQuery.Open;
      mainListviewGuide.clLoadListViewDataFromDataset(clViewDataQuery);
    finally
      clViewDataQuery.Free;
    End;
'''End;'''


Finally, the Guide takes the "MAIN_TEXT" field of the clicked data from the form with the "ReturnItemData" parameter and sends it to the edit on the previous page with the "ReturnItemObject" parameter.<br>
First, a SQLite database will be created with an "OperatingSystem" table, and sample data will be inserted into the table. When the user enters data into the search field and clicks the search button, the OnGuideQryClick event will be triggered, performing a database query based on the entered term.<br>


MyGuideForm.ReturnItemData := 'MAIN_TEXT';
The results of this query will be loaded into the list view, and when a user selects an item, a specific field (MAIN_TEXT) of that item will be transferred to an edit box (edtListNumber). The form will also include a title, layouts, and various components for user interaction. TclGuideForm will be used to display the search results and retrieve the selected data.<br>
MyGuideForm.ReturnItemObject := edtListNumber;
<br>
<i>Key steps:</i><br>


'''Code:'''<br>
Let's set up our connection to the sqlite database.<br>
<pre>
Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProductSales.db3', '');
</pre>


:'''Base Syntax'''
After that, we need to add BasisGuide to reach the desired guide information. After that, we add a listView to the Guide form and connect it to our form.<br>


'''Var''' 
<pre>
MyForm:TclForm;
mainListviewGuide = TClListView(MyGuideForm.clFindComponent('FormClListView'));
MyGuideForm : TclGuideForm;
mainListviewGuide.Align = alClient;
mainListviewGuide : TclListView;
mainListviewGuide.Visible = True;
lblTitle,lblListNumber :TClLabel;
</pre>
edtListNumber : TclEdit;
searchGuideEdit :TclProEdit;
searchRehButton,btnListNumber : TClProButton;
vertScrollBoxMain : TClVertScrollBox;
lytContent,lytListNumber:TClLayout;
searchRehLayout : TClLayout;<br>
'''procedure SetupSqlConnection;'''
  begin
    Clomosy.DBSQLServerConnect(<span style="color:red">'SQL Server','server_name','user_name','user_password','database_name',port</span>);
  end;<br> 
'''procedure Setup;'''
begin
    vertScrollBoxMain := MyForm.AddNewVertScrollBox(MyForm,'vertScrollBoxMain');
    vertScrollBoxMain.Align := alClient;<br> 
    lytContent:= MyForm.AddNewLayout(vertScrollBoxMain,'lytContent');
    lytContent.Align := alTop;
    lytContent.Height :=700;
end;<br>
'''procedure GuideListView;'''
begin
  mainListviewGuide := TClListView(MyGuideForm.clFindComponent('FormClListView'));
  mainListviewGuide.Align := alClient;
  mainListviewGuide.Visible := True;
end;<br>
'''procedure SetCaptionName;'''
begin
  lblTitle:= MyForm.AddNewLabel(MyForm,'lblTitle','COUNT SCREEN');
  lblTitle.Align:=alMostTop;
  lblTitle.Margins.Left:=100;
  lblTitle.Height :=30;
  lblTitle.StyledSettings := ssFamily;
  lblTitle.TextSettings.Font.Size:= 20;
end;<br>
'''Procedure OnGuideQryClick;'''
  var
    clViewDataQuery :TclSQLQuery;
  begin
      clViewDataQuery:=TclSQLQuery.Create(Nil);
    Try
      clViewDataQuery.Connection := Clomosy.DBSQLServerConnection;
      clViewDataQuery.SQL.Text :='<span style="color:red">SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%')</span>;
      clViewDataQuery.Open;
      mainListviewGuide.clLoadListViewDataFromDataset(clViewDataQuery);
    finally
      clViewDataQuery.Free;
    End;
  End;<br>
'''procedure GuideSearchView;'''
  begin
    searchRehLayout := MyGuideForm.AddNewLayout(MyGuideForm,'searchRehLayout');
    searchRehLayout.Align:=ALTop;
    searchRehLayout.Height := 50;<br>  
    searchGuideEdit:= MyGuideForm.AddNewProEdit(searchRehLayout,'searchGuideEdit','Search...');
    clComponent.SetupComponent(searchGuideEdit,'{"Align" : "Client","MarginTop":10,"Width" :180, "Height":50,
    "RoundHeight":10,"RoundWidth":10,"BorderColor":"#be92e0","BorderWidth":2}');<br>   
    searchRehButton:= MyGuideForm.AddNewProButton(searchRehLayout,'searchRehButton',<nowiki>''</nowiki>);
    clComponent.SetupComponent(searchRehButton,'{"Align" : "Right","Width" :60,"Height":40,
    "RoundHeight":10, "RoundWidth":10,"BorderColor":"#be92e0","BorderWidth":2,
      "ImgUrl":"https://images.freeimages.com/fic/images/icons/573/must_have/48/search.png"
    }');<br>   
    MyGuideForm.AddNewEvent(searchRehButton,tbeOnClick,'OnGuideQryClick');
  end;<br>
'''procedure OnListBtnClick'''
  begin
    MyGuideForm := TclGuideForm.Create(Self);
    TClButton(MyGuideForm.ClFindComponent('BtnFormMenu')).Visible := False;
    GuideListView;
    GuideSearchView;
    MyGuideForm.ReturnItemData := 'MAIN_TEXT';
    MyGuideForm.ReturnItemObject := edtListNumber;
    MyGuideForm.Run;
  End;<br>
'''procedure SetMainView;'''
  begin   
    lytListNumber        := MyForm.AddNewLayout(MyForm,'lytListNumber');
    lytListNumber.Align  := alTop;
    lytListNumber.Margins.Top := 10;
    lytListNumber.Height := 25;
    lytListNumber.Width  := 340;<br>   
    lblListNumber              := MyForm.AddNewLabel(lytListNumber,'lblListNumber','List Number:');
    lblListNumber.Align        := alMostLeft;
    lblListNumber.Width        := 140;
    lblListNumber.Margins.Left := 10;<br>   
    edtListNumber      := MyForm.AddNewEdit(lytListNumber,'edtListNumber','List Number');
    edtListNumber.Align := alLeft;
    edtListNumber.Width := 140;<br>   
    btnListNumber:= MyForm.AddNewProButton(lytListNumber,'btnListNumber',<nowiki>''</nowiki>);
    clComponent.SetupComponent(btnListNumber,'{"Align" : "Right","Width" :50,"Height":60,"MarginRight":10,
    "RoundHeight":10, "RoundWidth":10,"BorderColor":"#be92e0","BorderWidth":2,
      "ImgUrl":"https://images.freeimages.com/fic/images/icons/573/must_have/48/search.png"
    }');
    MyForm.AddNewEvent(btnListNumber,tbeOnClick,'OnListBtnClick');
  end;<br>
'''begin'''
  MyForm:=TclForm.Create(Self);
  MyForm.SetFormColor('#ffffff','#cebade',clGVertical);
  Setup;
  SetCaptionName;
  SetMainView; 
  SetupSqlConnection;
  MyForm.Run;
'''end;'''


:'''TRObject Syntax'''
After that, when we click on the button on the edit we wrote, it goes to the database and finds the value sought here and transfers it to the ListView.<br>


  Var 
<pre>
    MyForm:TclForm;
void OnGuideQryClick;
    MyGuideForm : TclGuideForm;
var
    mainListviewGuide : TclListView;
  Qry : TClSQLiteQuery;
    lblTitle,lblListNumber :TClLabel;
{
    edtListNumber : TclEdit;
  try
     searchGuideEdit :TclProEdit;
     Qry = Clomosy.DBSQLiteQueryWith('SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%'));
     searchRehButton,btnListNumber : TClProButton;
     Qry.OpenOrExecute;
     vertScrollBoxMain : TClVertScrollBox;
     if (Qry.Found)
     lytContent,lytListNumber:TClLayout;
     {
    searchRehLayout : TClLayout;
      mainListviewGuide.clLoadListViewDataFromDataset(Qry);
 
    }
  void SetupSqlConnection;
  {
    Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
  }
      
      
   void Setup;
   except
   {
    ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
    vertScrollBoxMain = MyForm.AddNewVertScrollBox(MyForm,'vertScrollBoxMain');
   }
    vertScrollBoxMain.Align = alClient;
}
   
</pre>
    lytContent= MyForm.AddNewLayout(vertScrollBoxMain,'lytContent');
 
    lytContent.Align = alTop;
Finally, the Guide takes the "MAIN_TEXT" field of the clicked data from the form with the "ReturnItemData" parameter and sends it to the edit on the previous page with the "ReturnItemObject" parameter.<br>
    lytContent.Height =700;
<pre>
   }
MyGuideForm.ReturnItemData = 'MAIN_TEXT';
MyGuideForm.ReturnItemObject = edtListNumber;
</pre>
 
 
<b>Example:</b><br>
<pre>
var
  MyForm:TclForm;
  MyGuideForm : TclGuideForm;
  mainListviewGuide : TclListView;
  lblTitle,lblListNumber :TClLabel;
  edtListNumber : TclEdit;
  searchGuideEdit :TclProEdit;
  searchRehButton,btnListNumber : TClProButton;
  vertScrollBoxMain : TClVertScrollBox;
  lytContent,lytListNumber:TClLayout;
   searchRehLayout : TClLayout;
    
    
  void GuideListView;
void Setup;
  {
{
    mainListviewGuide = TClListView(MyGuideForm.clFindComponent('FormClListView'));
  vertScrollBoxMain = MyForm.AddNewVertScrollBox(MyForm,'vertScrollBoxMain');
    mainListviewGuide.Align = alClient;
  vertScrollBoxMain.Align = alClient;
    mainListviewGuide.Visible = True;
  }
    
    
   void SetCaptionName;
   lytContent= MyForm.AddNewLayout(vertScrollBoxMain,'lytContent');
  {
  lytContent.Align = alTop;
    lblTitle= MyForm.AddNewLabel(MyForm,'lblTitle','COUNT SCREEN');
  lytContent.Height =700;
    lblTitle.Align=alMostTop;
}
    lblTitle.Margins.Left=100;
    lblTitle.Height =30;
    lblTitle.StyledSettings = ssFamily;
    lblTitle.TextSettings.Font.Size= 20;
  }
    
    
   void OnGuideQryClick;
void SetCaptionName;
  var
{
    clViewDataQuery :TclSQLQuery;
  lblTitle= MyForm.AddNewLabel(MyForm,'lblTitle','COUNT SCREEN');
   {
   lblTitle.Align=alMostTop;
    clViewDataQuery=TclSQLQuery.Create(Nil);
  lblTitle.Margins.Left=100;
    Try
  lblTitle.Height =30;
      clViewDataQuery.Connection = Clomosy.DBSQLServerConnection;
  lblTitle.StyledSettings = ssFamily;
      clViewDataQuery.SQL.Text ='SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%');
   lblTitle.TextSettings.Font.Size= 20;
      clViewDataQuery.Open;
}
      mainListviewGuide.clLoadListViewDataFromDataset(clViewDataQuery);
void GuideListView;
     finally
{
       clViewDataQuery.Free;
  mainListviewGuide = TClListView(MyGuideForm.clFindComponent('FormClListView'));
  mainListviewGuide.Align = alClient;
  mainListviewGuide.Visible = True;
}
 
void OnGuideQryClick;
var
  Qry : TClSQLiteQuery;
{
  try
    Qry = Clomosy.DBSQLiteQueryWith('SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%'));
    Qry.OpenOrExecute;
    if (Qry.Found)
     {
       mainListviewGuide.clLoadListViewDataFromDataset(Qry);
     }
     }
  }
 
  void GuideSearchView;
  {
    searchRehLayout = MyGuideForm.AddNewLayout(MyGuideForm,'searchRehLayout');
    searchRehLayout.Align=ALTop;
    searchRehLayout.Height = 50;
      
      
     searchGuideEdit= MyGuideForm.AddNewProEdit(searchRehLayout,'searchGuideEdit','Search...');
  except
    clComponent.SetupComponent(searchGuideEdit,'{"Align" : "Client","MarginTop":10,"Width" :180, "Height":50,
     ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
    "RoundHeight":10,"RoundWidth":10,"BorderColor":"#be92e0","BorderWidth":2}');
  }
   
}
    searchRehButton= MyGuideForm.AddNewProButton(searchRehLayout,'searchRehButton',<nowiki>''</nowiki>);
    clComponent.SetupComponent(searchRehButton,'{"Align" : "Right","Width" :60,"Height":40,
void GuideSearchView;
    "RoundHeight":10, "RoundWidth":10,"BorderColor":"#be92e0","BorderWidth":2,
{
    "ImgUrl":"https://images.freeimages.com/fic/images/icons/573/must_have/48/search.png"
  searchRehLayout = MyGuideForm.AddNewLayout(MyGuideForm,'searchRehLayout');
    }');
  searchRehLayout.Align=ALTop;
   
  searchRehLayout.Height = 50;
    MyGuideForm.AddNewEvent(searchRehButton,tbeOnClick,'OnGuideQryClick');
 
   }
  searchGuideEdit= MyGuideForm.AddNewProEdit(searchRehLayout,'searchGuideEdit','Search...');
  searchGuideEdit.Align=ALClient;
  searchGuideEdit.Height = 50;
  searchGuideEdit.Width = 180;
  searchGuideEdit.Margins.Top = 10;
  searchGuideEdit.clProSettings.IsRound = True;
  searchGuideEdit.clProSettings.RoundHeight = 10;
  searchGuideEdit.clProSettings.RoundWidth = 10;
  searchGuideEdit.clProSettings.BorderColor = clAlphaColor.clHexToColor('#be92e0');
  searchGuideEdit.clProSettings.BorderWidth = 2;
  searchGuideEdit.SetclProSettings(searchGuideEdit.clProSettings);
 
  searchRehButton= MyGuideForm.AddNewProButton(searchRehLayout,'searchRehButton','');
  searchRehButton.Align=ALRight;
  searchRehButton.Height = 40;
  searchRehButton.Width = 60;
  searchRehButton.clProSettings.IsRound = True;
  searchRehButton.clProSettings.RoundHeight = 10;
  searchRehButton.clProSettings.RoundWidth = 10;
  searchRehButton.clProSettings.BorderColor = clAlphaColor.clHexToColor('#be92e0');
  searchRehButton.clProSettings.BorderWidth = 2;
  searchRehButton.clProSettings.PictureSource = 'https://clomosy.com/demos/searchBtn.png';
  searchRehButton.SetclProSettings(searchRehButton.clProSettings);
  MyGuideForm.AddNewEvent(searchRehButton,tbeOnClick,'OnGuideQryClick');
}
 
void OnListBtnClick
{
  MyGuideForm = TclGuideForm.Create(Self);
  TClButton(MyGuideForm.ClFindComponent('BtnFormMenu')).Visible = False;
  GuideListView;
  GuideSearchView;
  MyGuideForm.ReturnItemData = 'MAIN_TEXT';
  MyGuideForm.ReturnItemObject = edtListNumber;
  MyGuideForm.Run;
}
void SetMainView;
{    
  lytListNumber        = MyForm.AddNewLayout(MyForm,'lytListNumber');
  lytListNumber.Align  = alTop;
  lytListNumber.Margins.Top = 10;
  lytListNumber.Height = 25;
  lytListNumber.Width  = 340;
 
  lblListNumber              = MyForm.AddNewLabel(lytListNumber,'lblListNumber','List Number:');
  lblListNumber.Align        = alMostLeft;
  lblListNumber.Width        = 140;
  lblListNumber.Margins.Left = 10;
 
  edtListNumber      = MyForm.AddNewEdit(lytListNumber,'edtListNumber','List Number');
  edtListNumber.Align = alLeft;
  edtListNumber.Width = 140;
    
    
   void OnListBtnClick
   btnListNumber= MyForm.AddNewProButton(lytListNumber,'btnListNumber','');
  btnListNumber.Align = AlRight;
  btnListNumber.Width = 50;
  btnListNumber.Height = 60;
  btnListNumber.Margins.Right = 10;
  btnListNumber.clProSettings.IsRound = True;
  btnListNumber.clProSettings.RoundHeight = 10;
  btnListNumber.clProSettings.RoundWidth = 10;
  btnListNumber.clProSettings.BorderColor = clAlphaColor.clHexToColor('#be92e0');
  btnListNumber.clProSettings.BorderWidth = 2;
  btnListNumber.clProSettings.PictureSource = 'https://clomosy.com/demos/searchBtn.png';
  btnListNumber.SetclProSettings(btnListNumber.clProSettings);
  MyForm.AddNewEvent(btnListNumber,tbeOnClick,'OnListBtnClick');
}
 
  void SqLiteInsertData;
   {
   {
     MyGuideForm = TclGuideForm.Create(Self);
     try
     TClButton(MyGuideForm.ClFindComponent('BtnFormMenu')).Visible = False;
      Clomosy.DBSQLiteQuery.Sql.Text = '
     GuideListView;
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (1, ''Vista'',''Microsoft Windows'',''tablet'', 200);
     GuideSearchView;
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''XP'',''Microsoft Windows'',''tablet'', 500);
     MyGuideForm.ReturnItemData = 'MAIN_TEXT';
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Microsoft Windows'',''computer'', 104);
     MyGuideForm.ReturnItemObject = edtListNumber;
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Public Beta'',''MacOS'',''computer'', 400);
     MyGuideForm.Run;
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (2, ''Tiger'',''MacOS'',''tablet'', 350);
  }
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Leopard'',''MacOS'',''computer'', 125);
 
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (3, ''Lollipop'',''Android'',''mobile'', 325);
  void SetMainView;
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Android'',''tablet'', 123);
  {   
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (4, ''Gnome'',''Pardus'',''computer'', 300);
    lytListNumber        = MyForm.AddNewLayout(MyForm,'lytListNumber');
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Raspberry'',''Pardus'',''computer'', 175);
     lytListNumber.Align  = alTop;
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (5, ''Tiger'',''MacOS'',''mobile'', 10);
    lytListNumber.Margins.Top = 10;
     INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''MacOS'',''ipad'', 104);';
    lytListNumber.Height = 25;
      Clomosy.DBSQLiteQuery.OpenOrExecute;
    lytListNumber.Width  = 340;
     
   
      ShowMessage('Adding data to the table was successful!');
    lblListNumber              = MyForm.AddNewLabel(lytListNumber,'lblListNumber','List Number:');
     except
     lblListNumber.Align        = alMostLeft;
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    lblListNumber.Width        = 140;
    }
    lblListNumber.Margins.Left = 10;
   
    edtListNumber      = MyForm.AddNewEdit(lytListNumber,'edtListNumber','List Number');
     edtListNumber.Align = alLeft;
    edtListNumber.Width = 140;
   
    btnListNumber= MyForm.AddNewProButton(lytListNumber,'btnListNumber',<nowiki>''</nowiki>);
     clComponent.SetupComponent(btnListNumber,'{"Align" : "Right","Width" :50,"Height":60,"MarginRight":10,
     "RoundHeight":10, "RoundWidth":10,"BorderColor":"#be92e0","BorderWidth":2,
    "ImgUrl":"https://images.freeimages.com/fic/images/icons/573/must_have/48/search.png"}');
     MyForm.AddNewEvent(btnListNumber,tbeOnClick,'OnListBtnClick');
   }
   }
    
    
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
   {
   {
     MyForm=TclForm.Create(Self);
     try
    MyForm.SetFormColor('#ffffff','#cebade',clGVertical);
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProductSales.db3', '');
    Setup;
    SetCaptionName;
      // Check if the table exists
     SetMainView; 
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="OperatingSystem";';
    SetupSqlConnection;
      Clomosy.DBSQLiteQuery.OpenOrExecute;
     MyForm.Run;
     
      // 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 OperatingSystem (
                                        id INTEGER NOT NULL,
                                        model TEXT NOT NULL,
                                        operating_system TEXT NOT NULL,
                                        device_type TEXT NOT NULL,
                                        sales_figure INTEGER NOT NULL
                                          )';
        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);
     }
   }
   }


'''Output:'''<br>
{
  MyForm = TclForm.Create(Self);
  MyForm.SetFormColor('#ffffff','#cebade',clGVertical);
  Setup;
  SetCaptionName;
  SetMainView; 
  SqLiteConnectionCreateTable;
  MyForm.Run;
}
</pre>
 
<b>Output:</b><br>
<gallery widths="300px" heights="500px" align="center" mode="nolines">
<gallery widths="300px" heights="500px" align="center" mode="nolines">
File: ExampleMainScreen.png | ''MyForm Screen''
File: ExampleMainScreen.png | ''MyForm Screen''
Line 278: Line 291:
</gallery>
</gallery>


== Also See ==
<h2> See Also </h2>
* [[Virtual Keyboard]]
* [[Virtual Keyboard]]
* [[TclForm]]
{{#seo:|title=TclGuideForm Using in Clomosy - Clomosy Docs}}
{{#seo:|description=TclGuideForm is a customized guide for querying and transferring data between forms, allowing efficient data retrieval and interaction.}}

Latest revision as of 13:59, 24 December 2024

It is a customized guide form. With the customized guide, it returns only the data that is queried without accessing all the data. In another use case, when data selected from a page search needs to be transferred to the previous page, the "TclGuideForm" component is used.

Before using these features, the form must be initialized.
An object of the TclGuideForm class should be defined.

var
   GuideForm1 : TclGuideForm;

The defined object must be created using the "Create" function.

{
  GuideForm1 = TclGuideForm.Create(Self);
  GuideForm1.Run;
}

The features are provided in the table below.

Feature Use of Definition
ReturnItemData GuideForm1.ReturnItemData = 'MAIN_TEXT'; The value of the desired field from the data clicked on in the list on the form page is retrieved and displayed in the next content. The name of the selected field must be written. In the example, the value from the "MAIN_TEXT" field is retrieved.
ReturnItemObject GuideForm1.ReturnItemObject = edtListNumber; The value returned from the previously selected field is passed. In the example, the data has been transferred to a TclEdit component named "edtListNumber".


Example

In this example, a TclForm will be created, containing a list view (TclListView), an interactive search field (TclProEdit), and a TclGuideForm to display data.

First, a SQLite database will be created with an "OperatingSystem" table, and sample data will be inserted into the table. When the user enters data into the search field and clicks the search button, the OnGuideQryClick event will be triggered, performing a database query based on the entered term.

The results of this query will be loaded into the list view, and when a user selects an item, a specific field (MAIN_TEXT) of that item will be transferred to an edit box (edtListNumber). The form will also include a title, layouts, and various components for user interaction. TclGuideForm will be used to display the search results and retrieve the selected data.

Key steps:

Let's set up our connection to the sqlite database.

Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProductSales.db3', '');

After that, we need to add BasisGuide to reach the desired guide information. After that, we add a listView to the Guide form and connect it to our form.

mainListviewGuide = TClListView(MyGuideForm.clFindComponent('FormClListView'));
mainListviewGuide.Align = alClient;
mainListviewGuide.Visible = True;

After that, when we click on the button on the edit we wrote, it goes to the database and finds the value sought here and transfers it to the ListView.

void OnGuideQryClick;
var
  Qry : TClSQLiteQuery;
{
  try
    Qry = Clomosy.DBSQLiteQueryWith('SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%'));
    Qry.OpenOrExecute;
    if (Qry.Found)
    {
      mainListviewGuide.clLoadListViewDataFromDataset(Qry);
    }
    
  except
    ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
  } 
}

Finally, the Guide takes the "MAIN_TEXT" field of the clicked data from the form with the "ReturnItemData" parameter and sends it to the edit on the previous page with the "ReturnItemObject" parameter.

MyGuideForm.ReturnItemData = 'MAIN_TEXT';
MyGuideForm.ReturnItemObject = edtListNumber;


Example:

 var
  MyForm:TclForm;
  MyGuideForm : TclGuideForm;
  mainListviewGuide : TclListView;
  lblTitle,lblListNumber :TClLabel;
  edtListNumber : TclEdit;
  searchGuideEdit :TclProEdit;
  searchRehButton,btnListNumber : TClProButton;
  vertScrollBoxMain : TClVertScrollBox;
  lytContent,lytListNumber:TClLayout;
  searchRehLayout : TClLayout;
  
void Setup;
{
  vertScrollBoxMain = MyForm.AddNewVertScrollBox(MyForm,'vertScrollBoxMain');
  vertScrollBoxMain.Align = alClient;
  
  lytContent= MyForm.AddNewLayout(vertScrollBoxMain,'lytContent');
  lytContent.Align = alTop;
  lytContent.Height =700;
}
  
void SetCaptionName;
{
  lblTitle= MyForm.AddNewLabel(MyForm,'lblTitle','COUNT SCREEN');
  lblTitle.Align=alMostTop;
  lblTitle.Margins.Left=100;
  lblTitle.Height =30;
  lblTitle.StyledSettings = ssFamily;
  lblTitle.TextSettings.Font.Size= 20;
}
void GuideListView;
{
  mainListviewGuide = TClListView(MyGuideForm.clFindComponent('FormClListView'));
  mainListviewGuide.Align = alClient;
  mainListviewGuide.Visible = True;
}

void OnGuideQryClick;
var
  Qry : TClSQLiteQuery;
{
  try
    Qry = Clomosy.DBSQLiteQueryWith('SELECT model AS MAIN_TEXT,operating_system AS SUB_TEXT FROM OperatingSystem WHERE model LIKE '+QuotedStr('%'+searchGuideEdit.text+'%'));
    Qry.OpenOrExecute;
    if (Qry.Found)
    {
      mainListviewGuide.clLoadListViewDataFromDataset(Qry);
    }
    
  except
    ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
  } 
}
 
void GuideSearchView;
{
  searchRehLayout = MyGuideForm.AddNewLayout(MyGuideForm,'searchRehLayout');
  searchRehLayout.Align=ALTop;
  searchRehLayout.Height = 50;
  
  searchGuideEdit= MyGuideForm.AddNewProEdit(searchRehLayout,'searchGuideEdit','Search...');
  searchGuideEdit.Align=ALClient;
  searchGuideEdit.Height = 50;
  searchGuideEdit.Width = 180;
  searchGuideEdit.Margins.Top = 10;
  searchGuideEdit.clProSettings.IsRound = True;
  searchGuideEdit.clProSettings.RoundHeight = 10;
  searchGuideEdit.clProSettings.RoundWidth = 10;
  searchGuideEdit.clProSettings.BorderColor = clAlphaColor.clHexToColor('#be92e0');
  searchGuideEdit.clProSettings.BorderWidth = 2;
  searchGuideEdit.SetclProSettings(searchGuideEdit.clProSettings);
  
  searchRehButton= MyGuideForm.AddNewProButton(searchRehLayout,'searchRehButton','');
  searchRehButton.Align=ALRight;
  searchRehButton.Height = 40;
  searchRehButton.Width = 60;
  searchRehButton.clProSettings.IsRound = True;
  searchRehButton.clProSettings.RoundHeight = 10;
  searchRehButton.clProSettings.RoundWidth = 10;
  searchRehButton.clProSettings.BorderColor = clAlphaColor.clHexToColor('#be92e0');
  searchRehButton.clProSettings.BorderWidth = 2;
  searchRehButton.clProSettings.PictureSource = 'https://clomosy.com/demos/searchBtn.png';
  searchRehButton.SetclProSettings(searchRehButton.clProSettings);
  MyGuideForm.AddNewEvent(searchRehButton,tbeOnClick,'OnGuideQryClick');
}

void OnListBtnClick
{
  MyGuideForm = TclGuideForm.Create(Self);
  TClButton(MyGuideForm.ClFindComponent('BtnFormMenu')).Visible = False;
  GuideListView;
  GuideSearchView;
  MyGuideForm.ReturnItemData = 'MAIN_TEXT';
  MyGuideForm.ReturnItemObject = edtListNumber;
  MyGuideForm.Run;
}
 
void SetMainView;
{    
  lytListNumber        = MyForm.AddNewLayout(MyForm,'lytListNumber');
  lytListNumber.Align  = alTop;
  lytListNumber.Margins.Top = 10;
  lytListNumber.Height = 25;
  lytListNumber.Width  = 340;
  
  lblListNumber              = MyForm.AddNewLabel(lytListNumber,'lblListNumber','List Number:');
  lblListNumber.Align        = alMostLeft;
  lblListNumber.Width        = 140;
  lblListNumber.Margins.Left = 10;
  
  edtListNumber       = MyForm.AddNewEdit(lytListNumber,'edtListNumber','List Number');
  edtListNumber.Align = alLeft;
  edtListNumber.Width = 140;
  
  btnListNumber= MyForm.AddNewProButton(lytListNumber,'btnListNumber','');
  btnListNumber.Align = AlRight;
  btnListNumber.Width = 50;
  btnListNumber.Height = 60;
  btnListNumber.Margins.Right = 10;
  btnListNumber.clProSettings.IsRound = True;
  btnListNumber.clProSettings.RoundHeight = 10;
  btnListNumber.clProSettings.RoundWidth = 10;
  btnListNumber.clProSettings.BorderColor = clAlphaColor.clHexToColor('#be92e0');
  btnListNumber.clProSettings.BorderWidth = 2;
  btnListNumber.clProSettings.PictureSource = 'https://clomosy.com/demos/searchBtn.png';
  btnListNumber.SetclProSettings(btnListNumber.clProSettings);
  MyForm.AddNewEvent(btnListNumber,tbeOnClick,'OnListBtnClick');
}

   void SqLiteInsertData;
  {
    try
      Clomosy.DBSQLiteQuery.Sql.Text = '
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (1, ''Vista'',''Microsoft Windows'',''tablet'', 200);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''XP'',''Microsoft Windows'',''tablet'', 500);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Microsoft Windows'',''computer'', 104);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Public Beta'',''MacOS'',''computer'', 400);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (2, ''Tiger'',''MacOS'',''tablet'', 350);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Leopard'',''MacOS'',''computer'', 125);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (3, ''Lollipop'',''Android'',''mobile'', 325);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Android'',''tablet'', 123);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (4, ''Gnome'',''Pardus'',''computer'', 300);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Raspberry'',''Pardus'',''computer'', 175);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (5, ''Tiger'',''MacOS'',''mobile'', 10);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''MacOS'',''ipad'', 104);';
      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 + 'DBProductSales.db3', '');
 
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="OperatingSystem";';
      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 OperatingSystem (
                                        	id INTEGER NOT NULL,
                                        	model TEXT NOT NULL,
                                        	operating_system TEXT NOT NULL,
                                        	device_type TEXT NOT NULL,
                                        	sales_figure INTEGER NOT NULL
                                          )';
        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);
    }
  }

{
  MyForm = TclForm.Create(Self);
  MyForm.SetFormColor('#ffffff','#cebade',clGVertical);
  Setup;
  SetCaptionName;
  SetMainView;  
  SqLiteConnectionCreateTable;
  MyForm.Run;
}

Output:

See Also