From Clomosy Docs
ClomosyAdmin (talk | contribs) No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
| Line 74: | Line 74: | ||
* [[System_Library#Cl_Utilities_Functions | Cl Utilities Functions]] | * [[System_Library#Cl_Utilities_Functions | Cl Utilities Functions]] | ||
* [[File Handling]] | * [[File Handling]] | ||
{{#seo:|description=}} | {{#seo:|description=Learn how to use the clLoadFromFile function to read file content in Clomosy. Retrieve data efficiently with examples and error handling guidance!}} | ||
Revision as of 10:25, 24 December 2024
function clLoadFromFile(const FilePath:String): String;
FilePath : The file path to be read must be specified. This typically includes a directory and a file name, such as 'C:\Users\User\Documents\cl.txt'.
This function is used to read text or data from a file. The retrieved text can be assigned to an object (such as TclMemo, TclLabel) or a string data type.
If the file exists, it retrieves the content of the file and assigns it to the desired object or variable (String). If no file path is specified, the file is saved to the directory where the Clomosy Learn application is located.
An error may occur if the specified file is not present in the directory.
The general usage is as follows:
//str:String;
str = clLoadFromFile(Clomosy.AppFilesPath+'cl.txt');
str = clLoadFromFile('cl.txt');
Example
When the button is clicked, if the specified file exists in the directory, its content is retrieved and transferred to the TclMemo object.
var
Form1:TclForm;
Memo1 : TclMemo;
Layout1 : TclLayout;
BtnShow : TclProButton;
void BtnShowOnClick;
{
//ShowMessage(Clomosy.AppFilesPath);
if (clFileExists('cl.txt',Clomosy.AppFilesPath))
{
Memo1.Text = clLoadFromFile(Clomosy.AppFilesPath+'cl.txt');
}
Else
{
clShowMessage('The file could not be found in the specified directory!');
}
}
{
Form1 = TclForm.Create(Self);
Memo1 = Form1.AddNewMemo(Form1,'Memo1','');
Memo1.Align = alMostTop;
Memo1.Height = 200;
Memo1.Width = 150;
Memo1.Margins.Left= 10;
Memo1.Margins.Right= 10;
Memo1.Margins.Top= 10;
Memo1.TextSettings.WordWrap = True;
Layout1 = Form1.AddNewLayout(Form1,'Layout1');
Layout1.Align=ALTop;
Layout1.Height = 50;
BtnShow = Form1.AddNewProButton(Layout1,'BtnShow','');
BtnShow.Align = AlRight;
BtnShow.Margins.Right = 10;
BtnShow.Width = 70;
Form1.AddNewEvent(BtnShow,tbeOnClick,'BtnShowOnClick');
Form1.SetImage(BtnShow,'https://clomosy.com/demos/add-list.png');
Form1.Run;
}