From Clomosy Docs

Revision as of 10:25, 24 April 2025 by ClomosyManager (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

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

xCaption : A hint or message to be displayed when the Text property is empty.

TclMemo is a multiline text editing control, providing text scrolling. Use TclMemo to place a standard multiline edit control on a form. Multiline edit boxes allow the user to enter more than one line of text. They are appropriate for representing large amounts of text. The text in the memo control can be edited as a whole or line by line.

Feature Use of Definition
TclMemo Memo1 : TclMemo; A variable belonging to the TclMemo class is created.
AddNewMemo Memo1 = Form1.AddNewMemo(Form1,'Memo1','Test Memo Message'); A new TclMemo is added to the form.
ReadOnly Memo1.ReadOnly = True; If the value of the component is set to true, it makes the component read-only.
Add Memo1.Lines.Add('New row'); 'Add' is used to add data to new row in TclMemo.
Count integerValue = Memo1.Lines.Count; 'Count' is used to get the number of rows in TclMemo.
Delete Memo1.Lines.Delete(i); //i : number of rows to be deleted Used to delete a line in TclMemo. You must specify the number of rows as a parameter in the delete command.
Clear Memo1.Lines.Clear; Clears all text inside the object.
WordWrap Memo1.TextSettings.WordWrap = True; When a very long text is typed in TclMemo, the line scrolls sideways. It is used to prevent this, that is, to move to the bottom row when the end of the row is reached.
SelStart Memo1.SelStart = Length(Memo1.Text); It positions the cursor at the end of the text by setting the length of the text within the TclMemo.
ScrollTo Memo1.ScrollTo(0,Memo1.Lines.Count*Memo1.Lines.Count,True); In the TclMemo component, the ScrollTo method performs a scrolling operation.

In the example, it scrolls downward vertically by a multiple of its height.

LoadFromFile Memo1.lines.LoadFromFile(MyFileStr,0); //MyFileStr: specifies the file path Using the Lines property of the TclMemo component in Clomosy, text can be loaded from a file. The LoadFromFile method loads the text from the specified file path into the TclMemo component, and this text is then displayed within the component.
SavetoFile Memo1.Lines.SavetoFile(MyFileStr,0); Using the Lines property of the TclMemo component in Clomosy, text can be saved to a file. The SaveToFile method writes the lines of text from the TclMemo component to the specified file path. Passing 0 as the second parameter indicates that the operation will be performed with default options.


Example 1


In the example, a text is entered into a TclProEdit. This text is added to TclMemo via the button. We have implemented a simple application for the use of TclMemo. You can improve this application.

var
  MyForm:TclForm;
  topLyt, btnLyt, bottomLyt : TclLayout;
  noteEdt : TclProEdit;
  addBtn : TclProButton;
  noteAddLbl, notesLbl :TclProLabel;
  mainPanel : TclProPanel;
  noteMemo : TclMemo;
 
void BtnOnClick;
{
  noteMemo.Lines.Add('* '+noteEdt.Text);
  noteEdt.Text = '';
noteMemo.ScrollTo(0,noteMemo.Lines.Count*noteMemo.Lines.Count,True);
}
 
{
  MyForm = TclForm.Create(Self);
   
  mainPanel=MyForm.AddNewProPanel(MyForm,'mainPanel');
  mainPanel.Align = AlClient;
  mainPanel.Margins.Right = 5;
  mainPanel.Margins.Left = 5;
  mainPanel.Margins.Bottom = 5;
  mainPanel.Margins.Top = 5;
  mainPanel.clProSettings.IsRound = True;
  mainPanel.clProSettings.RoundHeight = 60;
  mainPanel.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3bf5c0');
  mainPanel.clProSettings.BorderWidth = 1;
  mainPanel.SetclProSettings(mainPanel.clProSettings);
   
  topLyt = MyForm.AddNewLayout(mainPanel,'topLyt');
  topLyt.Align=ALMostTop;
  topLyt.Height = 150;
   
  noteAddLbl = MyForm.AddNewProLabel(topLyt,'noteAddLbl','Add Note');
  noteAddLbl.Align = AlMostTop;
  noteAddLbl.Width = 150;
  noteAddLbl.Height = 20;
  noteAddLbl.Margins.Left = 10;
  noteAddLbl.Margins.Top = 20;
  noteAddLbl.clProSettings.FontColor = clAlphaColor.clHexToColor('#030303');
  noteAddLbl.clProSettings.FontSize = 15;
  noteAddLbl.clProSettings.FontVertAlign = palcenter;
  noteAddLbl.clProSettings.FontHorzAlign = palLeading;
  noteAddLbl.clProSettings.TextSettings.Font.Style = [fsBold];
  noteAddLbl.SetclProSettings(noteAddLbl.clProSettings);
  
   
  noteEdt = MyForm.AddNewProEdit(topLyt,'noteEdt','Enter your note...');
  noteEdt.Align = AlTop;
  noteEdt.Height = 45;
  noteEdt.Margins.Right = 10;
  noteEdt.Margins.Left = 10;
  noteEdt.Margins.Top = 10;
  noteEdt.clProSettings.IsRound = True;
  noteEdt.clProSettings.RoundHeight = 10;
  noteEdt.clProSettings.RoundWidth = 10; 
  noteEdt.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3bf5c0');
  noteEdt.clProSettings.BorderWidth = 1;
  noteEdt.SetclProSettings(noteEdt.clProSettings); 
  
  btnLyt = MyForm.AddNewLayout(topLyt,'btnLyt');
  btnLyt.Align=ALBottom;
  btnLyt.Height = 50;
  
  addBtn = MyForm.AddNewProButton(btnLyt,'addBtn','');
  addBtn.Align = AlRight;
  addBtn.Width = 70;
  addBtn.Margins.Right = 10;
  addBtn.clProSettings.PictureSource = 'https://clomosy.com/demos/add-list.png';
  addBtn.SetclProSettings(addBtn.clProSettings);
  MyForm.AddNewEvent(addBtn,tbeOnClick,'BtnOnClick');
  
  bottomLyt = MyForm.AddNewLayout(mainPanel,'bottomLyt');
  bottomLyt.Align=ALTop;
  bottomLyt.Height = 100;
  bottomLyt.Margins.Top = 20;
  
  notesLbl = MyForm.AddNewProLabel(bottomLyt,'notesLbl','My Notes');
  notesLbl.Align = AlMostTop;
  notesLbl.Width = 150;
  notesLbl.Height = 20;
  notesLbl.Margins.Left = 10;
  notesLbl.Margins.Top = 20;
  notesLbl.clProSettings.FontColor = clAlphaColor.clHexToColor('#030303');
  notesLbl.clProSettings.FontSize = 15;
  notesLbl.clProSettings.FontVertAlign = palcenter;
  notesLbl.clProSettings.FontHorzAlign = palLeading;
  notesLbl.clProSettings.TextSettings.Font.Style = [fsBold];
  notesLbl.SetclProSettings(notesLbl.clProSettings);
  
  noteMemo = MyForm.AddNewMemo(bottomLyt,'noteMemo','');
  noteMemo.Align = alTop;
  noteMemo.Height = 200;
  noteMemo.Width = 150;
  noteMemo.Margins.Left= 10;
  noteMemo.Margins.Right= 10; 
  noteMemo.Margins.Top= 10;
  noteMemo.ReadOnly = True;
  noteMemo.TextSettings.WordWrap = True;
  
  MyForm.Run;
}

Output:
TclMemoExampleScreen.png


Example 2 (LoadFromFile):


The example creates a form (TclForm) and a memo component (TclMemo), and adds data to a text file at a specified file path, then loads this data into the memo component. First, the Form1 and Memo1 objects are created, and the memo component is added to the form. The SaveFileAndAddData procedure opens or rewrites the file.txt file at the specified file path, adds two lines of text, and then closes the file. In the main program block, if the file.txt file does not exist, the SaveFileAndAddData procedure is called to create the file. Then, the contents of the file.txt file are loaded into the Memo1 component using LoadFromFile.

var
  Form1 : TclForm;
  Memo1: TclMemo;
  MyFileStr: string;

void SaveFileAndAddData;
var
  myFile : TextFile;
{
  AssignFile(myFile, Clomosy.AppFilesPath+'file.txt');
  ReWrite(myFile);
  WriteLn(myFile, 'Task 1');
  WriteLn(myFile, 'Task 2');
  ShowMessage('Lines have been added to the file.'); 
  CloseFile(myFile);
}
  
{
  Form1 = TclForm.Create(self);
  Memo1 = Form1.AddNewMemo(Form1,'Memo1', '--');
  Memo1.Align = alCenter;
  Memo1.Height = Form1.clHeight/2;
  Memo1.Width = 300;
  try
    If not (clFileExists('file.txt',Clomosy.AppFilesPath)) 
      SaveFileAndAddData;
    
    MyFileStr = Clomosy.AppFilesPath+'file.txt';
    
    // Upload file to Memo1
    Memo1.Lines.LoadFromFile(MyFileStr, 0);
    
  except
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
  }
  
  Form1.Run;
}

Example 3 (SaveToFile):


The example creates a form (TclForm) and a memo component (TclMemo), and writes text to a file at a specified path, then saves this text to the memo component. First, the Form1 and Memo1 objects are created, and the memo component is added to the form. The MyFileStr variable specifies the path to the text file. The program opens the file with AssignFile if it does not already exist, and adds three lines of text to the Memo1 component. Then, the SaveToFile method is used to save this text to the saveFile.txt file.

var
  Form1 : TclForm;
  Memo1: TclMemo;
  MyFileStr: string;
  myFile : TextFile;

{
  Form1 = TclForm.Create(self);
  Memo1 = Form1.AddNewMemo(Form1,'Memo1', '---');
  Memo1.Align = alCenter;
  Memo1.Height = Form1.clHeight/2;
  Memo1.Width = 300;
  
  MyFileStr = Clomosy.AppFilesPath+'saveFile.txt';
  try
    If not (clFileExists('saveFile.txt',Clomosy.AppFilesPath)) 
      AssignFile(myFile, Clomosy.AppFilesPath+'saveFile.txt');
    
    Memo1.Lines.Add('Row 1');
    Memo1.Lines.Add('Row 2');
    Memo1.Lines.Add('Row 3');
    // Upload saveFile to Memo1
    Memo1.Lines.SaveToFile(MyFileStr, 0);
    
  except
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
  }
  
  Form1.Run;
}

See Also