From Clomosy Docs

No edit summary
No edit summary
Line 14: Line 14:


'''Example:'''
'''Example:'''
If the file does not exist in the project directory, it saves the file. If the file exists, it adds a line to it.
When the application runs for the first time, it will not find the file, so it will add it to the file path and display a message.
When run for the second time, a line is added to the existing file.
:''Base Syntax''
:''Base Syntax''
  var
var
    strList:TclStringList;
  strList:TclStringList;
    fileStr:String;
  fileStr:String;
  begin
  i : Integer;
    strList := Clomosy.StringListNew;
begin
    fileStr := clPathCombine('File.Txt',Clomosy.AppFilesPath);
  strList := Clomosy.StringListNew;
    ShowMessage(fileStr);
  fileStr := clPathCombine('File.Txt',Clomosy.AppFilesPath);
 
    If clFileExists(fileStr,Clomosy.AppFilesPath) then
  If clFileExists(fileStr,Clomosy.AppFilesPath) then
  begin
    strList.Add('New Line 1');
    strList.SaveToFile(fileStr,0);
    ShowMessage('A line has been added to the existing file. To check, check your file via the file path. File path:'+#13#10+ fileStr);
  end else
  begin
    strList.SaveToFile(fileStr,0);
    ShowMessage('The file has been added to the directory. Directory path: '+#13#10+ fileStr)
  end
  if strList.Count <= 0 then
      ShowMessage('Empty!');
    else
     begin
     begin
       strList.Add('New Line 1');
       for i := 0 to strList.Count - 1 do
      strList.SaveToFile(fileStr,0);
        ShowMessage(Clomosy.StringListItemString(strList,i));
     end else
     end;
    begin
end;
      strList.SaveToFile(fileStr,0);
    end
  end;


:''TRObject Syntax''
:''TRObject Syntax''
  var
var
    strList:TclStringList;
  strList:TclStringList;
    fileStr:String;
  fileStr:String;
  {
  i : Integer;
    strList = Clomosy.StringListNew;
{
    fileStr = clPathCombine('File.Txt',Clomosy.AppFilesPath);
  strList = Clomosy.StringListNew;
    ShowMessage(fileStr);
  fileStr = clPathCombine('File.Txt',Clomosy.AppFilesPath);
 
    If clFileExists(fileStr,Clomosy.AppFilesPath)  
  If (clFileExists(fileStr,Clomosy.AppFilesPath))
    {
  {
      strList.Add('New Line 1');
    strList.Add('New Line 1');
      strList.SaveToFile(fileStr,0);
    strList.SaveToFile(fileStr,0);
     } else
    ShowMessage('A line has been added to the existing file. To check, check your file via the file path. File path:'+#13#10+ fileStr);
  } else
  {
    strList.SaveToFile(fileStr,0);
    ShowMessage('The file has been added to the directory. Directory path: '+#13#10+ fileStr)
  }
  if (strList.Count <= 0)
      ShowMessage('Empty!');
     else
     {
     {
       strList.SaveToFile(fileStr,0);
       for (i = 0 to strList.Count - 1)
        ShowMessage(Clomosy.StringListItemString(strList,i));
     }
     }
  }
}


= See Also =
= See Also =
* [[Controls| Controls]]
* [[Controls| Controls]]

Revision as of 08:21, 2 July 2024

clPathCombine is a function that is part of the Clomosy library. This function returns a string data by concatenating the file path and file name.

The general usage is as follows:

clPathCombine(FileNameString:WideString; CombinePathString:String);

FileNameString : Searched file name.

CombinePathString : The file path to merge.

For instance:

CombinedPath := clPathCombine('File.txt','C:\Document');
 // Now CombinedPath will be 'C:\Document\File.txt'.

Example:

If the file does not exist in the project directory, it saves the file. If the file exists, it adds a line to it. When the application runs for the first time, it will not find the file, so it will add it to the file path and display a message. When run for the second time, a line is added to the existing file.

Base Syntax
var
  strList:TclStringList;
  fileStr:String;
  i : Integer;
begin
  strList := Clomosy.StringListNew;
  fileStr := clPathCombine('File.Txt',Clomosy.AppFilesPath);

  If clFileExists(fileStr,Clomosy.AppFilesPath) then
  begin
    strList.Add('New Line 1');
    strList.SaveToFile(fileStr,0);
    ShowMessage('A line has been added to the existing file. To check, check your file via the file path. File path:'+#13#10+ fileStr);
  end else
  begin
    strList.SaveToFile(fileStr,0);
    ShowMessage('The file has been added to the directory. Directory path: '+#13#10+ fileStr)
  end
  if strList.Count <= 0 then
     ShowMessage('Empty!');
   else
   begin
     for i := 0 to strList.Count - 1 do
       ShowMessage(Clomosy.StringListItemString(strList,i));
   end;
end;
TRObject Syntax
var
  strList:TclStringList;
  fileStr:String;
  i : Integer;
{
  strList = Clomosy.StringListNew;
  fileStr = clPathCombine('File.Txt',Clomosy.AppFilesPath);

  If (clFileExists(fileStr,Clomosy.AppFilesPath))
  {
    strList.Add('New Line 1');
    strList.SaveToFile(fileStr,0);
    ShowMessage('A line has been added to the existing file. To check, check your file via the file path. File path:'+#13#10+ fileStr);
  } else
  {
    strList.SaveToFile(fileStr,0);
    ShowMessage('The file has been added to the directory. Directory path: '+#13#10+ fileStr)
  }
  if (strList.Count <= 0)
     ShowMessage('Empty!');
   else
   {
     for (i = 0 to strList.Count - 1)
       ShowMessage(Clomosy.StringListItemString(strList,i));
   }
}

See Also