From Clomosy Docs

(Created page with "TclFileStream enables applications to read from and write to a file on disk. Use TclFileStream to access the information in disk files. TclFileStream will open a named file and provide methods to read from or write to it. Pros: :Large Data Processing: It can handle very large data sizes, limited only by disk space. :Persistence: Data is persistent and remains available even after the application is closed. Cons: :Slower Access: File I/O operations are generally slower...")
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
TclFileStream enables applications to read from and write to a file on disk.
TclFileStream enables applications to read from and write to a file on disk.<br>


Use TclFileStream to access the information in disk files. TclFileStream will open a named file and provide methods to read from or write to it.
Use TclFileStream to access the information in disk files. TclFileStream will open a named file and provide methods to read from or write to it.<br>


Pros:
<b>Pros:</b>
:Large Data Processing: It can handle very large data sizes, limited only by disk space.
*Large Data Processing: It can handle very large data sizes, limited only by disk space.
:Persistence: Data is persistent and remains available even after the application is closed.
*Persistence: Data is persistent and remains available even after the application is closed.


Cons:
<b>Cons:</b>
:Slower Access: File I/O operations are generally slower than memory operations due to disk access delays.
*Slower Access: File I/O operations are generally slower than memory operations due to disk access delays.
:Disk I/O: Involves reading from and writing to disk, which can be slower and resource-intensive.
*Disk I/O: Involves reading from and writing to disk, which can be slower and resource-intensive.


<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"|Definition  
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition  
|-
|-
|TclFileStream || FileStream: TCLFileStream; || A variable belonging to the TclFileStream class is created.
|TclFileStream || FileStream: TCLFileStream; || A variable belonging to the TclFileStream class is created.
Line 18: Line 19:
|TCLFileStream.Create(filePath, fmCreate);|| FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate); //fmOpenRead - fmOpenWrite - fmOpenReadWrite - fmExclusive - fmShareExclusive - fmShareDenyWrite - fmShareDenyNone - fmCreate - fmClosed - fmInput - fmOutput - fmInOut|| When creating a new TclFileStream object on the form, it takes two parameters. The first parameter specifies the file path, and the second parameter indicates how the file will be opened. In the example, it creates the specified file and opens it in writing mode (fmCreate).
|TCLFileStream.Create(filePath, fmCreate);|| FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate); //fmOpenRead - fmOpenWrite - fmOpenReadWrite - fmExclusive - fmShareExclusive - fmShareDenyWrite - fmShareDenyNone - fmCreate - fmClosed - fmInput - fmOutput - fmInOut|| When creating a new TclFileStream object on the form, it takes two parameters. The first parameter specifies the file path, and the second parameter indicates how the file will be opened. In the example, it creates the specified file and opens it in writing mode (fmCreate).
|-
|-
|AsBase64 ||noteMemo.Lines.Text = FileStream.AsBase64; || Returns base64 string data.
|AsBase64 ||noteMemo.Lines.Text = FileStream.AsBase64; //noteMemo //TclMemo || Returns base64 string data.
|-
|-
|Free ||FileStream.Free; || It releases the memory occupied and destroys the object.
|Free ||FileStream.Free; || It releases the memory occupied and destroys the object.
|-
|Bitmap image (TclImage) transfer to TCLFileStream ||Img1.Bitmap.'''SaveToStream'''(FileStream); ||--
|-
|Transferring TCLFileStream data to bitmap image (TclImage) || Img1.Bitmap.'''LoadFromStream'''(FileStream);||--
|}
|}
</div>


'''Example:'''<br>
This example creates a form and adds an image, a text area, and a button onto it. A procedure named FileStreamExample first saves the image to a file (in fmCreate mode), then loads the same image from the file (in fmOpenRead mode), and finally places the Base64 code of the image into a text area.


:'''TRObject Syntax'''
<b>Example</b><br>


  var
This example creates a form and adds an image, a text area, and a button onto it. A procedure named FileStreamExample first saves the image to a file (in fmCreate mode), then loads the same image from the file (in fmOpenRead mode), and finally places the Base64 code of the image into a text area.<br>
    Form1:TCLForm;
    SourceImg : TclImage;
    noteMemo : TclMemo;
    btn1 : TclButton;
 
  void FileStreamExample;
  var
    FileStream: TCLFileStream;
  {
 
    // Save Img To File
    FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate);
    try
      SourceImg.Bitmap.SaveToStream(FileStream);
    finally
      FileStream.Free;
    }
   
    // Load Img From File
   
    FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmOpenRead);
    try
      SourceImg.Bitmap.LoadFromStream(FileStream);
      noteMemo.Lines.Text = FileStream.AsBase64;
    finally
      FileStream.Free;
    }
 
  }
 
  {
    Form1 = TCLForm.Create(Self);
   
    Form1.AddAssetFromUrl('https://clomosy.com/educa/ok.png');
    noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
    noteMemo.Align = alMostTop;
    noteMemo.Height = 200;
    noteMemo.StyledSettings = ssFamily;
    noteMemo.TextSettings.WordWrap = True;
   
    SourceImg = Form1.AddNewImage(Form1,'SourceImg');
    SourceImg.Align = alClient;
    Form1.setImage(SourceImg,'https://clomosy.com/educa/hint.png');
   
    btn1 = Form1.AddNewButton(Form1,'btn1','Upload');
    btn1.StyledSettings = ssFamily;
    btn1.TextSettings.Font.Size = 20;
    btn1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');
    btn1.Align = alBottom;
    Form1.AddNewEvent(btn1,tbeOnClick,'FileStreamExample');
   
    Form1.Run;
  }


 
<pre>
:'''Base Syntax'''
var
 
  Form1:TCLForm;
  var
  SourceImg : TclImage;
    Form1:TCLForm;
  noteMemo : TclMemo;
    SourceImg : TclImage;
  btn1 : TclButton;
    noteMemo : TclMemo;
    btn1 : TclButton;
void FileStreamExample;
 
var
  procedure FileStreamExample;
  FileStream: TCLFileStream;
  var
{
    FileStream: TCLFileStream;
  begin
  // Save Img To File
 
  FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate);
    // Save Img To File
  try
    FileStream := TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate);
    SourceImg.Bitmap.SaveToStream(FileStream);
    try
  finally
      SourceImg.Bitmap.SaveToStream(FileStream);
    FileStream.Free;
    finally
  }
      FileStream.Free;
 
    end;
  // Load Img From File
   
 
    // Load Img From File
  FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmOpenRead);
   
  try
    FileStream := TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmOpenRead);
    SourceImg.Bitmap.LoadFromStream(FileStream);
    try
    noteMemo.Lines.Text = FileStream.AsBase64;
      SourceImg.Bitmap.LoadFromStream(FileStream);
  finally
      noteMemo.Lines.Text := FileStream.AsBase64;
    FileStream.Free;
    finally
  }
      FileStream.Free;
    end;
}
 
  end;
   
   
  begin
{
    Form1 := TCLForm.Create(Self);
  Form1 = TCLForm.Create(Self);
   
 
    Form1.AddAssetFromUrl('https://clomosy.com/educa/ok.png');
  Form1.AddAssetFromUrl('https://clomosy.com/educa/ok.png');
    noteMemo := Form1.AddNewMemo(Form1,'noteMemo','---');
  noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
    noteMemo.Align := alMostTop;
  noteMemo.Align = alMostTop;
    noteMemo.Height := 200;
  noteMemo.Height = 200;
    noteMemo.StyledSettings := ssFamily;
  noteMemo.StyledSettings = ssFamily;
    noteMemo.TextSettings.WordWrap := True;
  noteMemo.TextSettings.WordWrap = True;
   
 
    SourceImg := Form1.AddNewImage(Form1,'SourceImg');
  SourceImg = Form1.AddNewImage(Form1,'SourceImg');
    SourceImg.Align := alClient;
  SourceImg.Align = alClient;
    Form1.setImage(SourceImg,'https://clomosy.com/educa/hint.png');
  Form1.setImage(SourceImg,'https://clomosy.com/educa/hint.png');
   
 
    btn1 := Form1.AddNewButton(Form1,'btn1','Upload');
  btn1 = Form1.AddNewButton(Form1,'btn1','Upload');
    btn1.StyledSettings := ssFamily;
  btn1.StyledSettings = ssFamily;
    btn1.TextSettings.Font.Size := 20;
  btn1.TextSettings.Font.Size = 20;
    btn1.TextSettings.FontColor := clAlphaColor.clHexToColor('#8a067c');
  btn1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');
    btn1.Align := alBottom;
  btn1.Align = alBottom;
    Form1.AddNewEvent(btn1,tbeOnClick,'FileStreamExample');
  Form1.AddNewEvent(btn1,tbeOnClick,'FileStreamExample');
   
 
    Form1.Run;
  Form1.Run;
  end;
}
 
</pre>
== See Also ==


<h2> See Also </h2>
* [[Components]]
* [[TclMemoryStream]]
* [[TclMemoryStream]]
* [[StreamToBase64]]
* [[StreamToBase64]]
Line 153: Line 95:
* [[Base64ToFile]]
* [[Base64ToFile]]
* [[Base64ToStream]]
* [[Base64ToStream]]
{{#seo:|title=TclFileStream in Clomosy - Clomosy Docs}}
{{#seo:|description=Explore TclFileStream in Clomosy! Handle file input and output operations with ease for efficient data streaming in your mobile apps.}}

Latest revision as of 13:11, 24 December 2024

TclFileStream enables applications to read from and write to a file on disk.

Use TclFileStream to access the information in disk files. TclFileStream will open a named file and provide methods to read from or write to it.

Pros:

  • Large Data Processing: It can handle very large data sizes, limited only by disk space.
  • Persistence: Data is persistent and remains available even after the application is closed.

Cons:

  • Slower Access: File I/O operations are generally slower than memory operations due to disk access delays.
  • Disk I/O: Involves reading from and writing to disk, which can be slower and resource-intensive.
Feature Use of Definition
TclFileStream FileStream: TCLFileStream; A variable belonging to the TclFileStream class is created.
TCLFileStream.Create(filePath, fmCreate); FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate); //fmOpenRead - fmOpenWrite - fmOpenReadWrite - fmExclusive - fmShareExclusive - fmShareDenyWrite - fmShareDenyNone - fmCreate - fmClosed - fmInput - fmOutput - fmInOut When creating a new TclFileStream object on the form, it takes two parameters. The first parameter specifies the file path, and the second parameter indicates how the file will be opened. In the example, it creates the specified file and opens it in writing mode (fmCreate).
AsBase64 noteMemo.Lines.Text = FileStream.AsBase64; //noteMemo //TclMemo Returns base64 string data.
Free FileStream.Free; It releases the memory occupied and destroys the object.


Example

This example creates a form and adds an image, a text area, and a button onto it. A procedure named FileStreamExample first saves the image to a file (in fmCreate mode), then loads the same image from the file (in fmOpenRead mode), and finally places the Base64 code of the image into a text area.

 var
   Form1:TCLForm;
   SourceImg : TclImage;
   noteMemo : TclMemo;
   btn1 : TclButton;
 
 void FileStreamExample;
 var
   FileStream: TCLFileStream;
 {
 
   // Save Img To File
   FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmCreate);
   try
     SourceImg.Bitmap.SaveToStream(FileStream);
   finally
     FileStream.Free;
   }
   
   // Load Img From File
   
   FileStream = TCLFileStream.Create(clPathCombine('ok.png',Clomosy.AppFilesPath), fmOpenRead);
   try
     SourceImg.Bitmap.LoadFromStream(FileStream);
     noteMemo.Lines.Text = FileStream.AsBase64;
   finally
     FileStream.Free;
   }
 
 }
 
 {
   Form1 = TCLForm.Create(Self);
   
   Form1.AddAssetFromUrl('https://clomosy.com/educa/ok.png');
   noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
   noteMemo.Align = alMostTop;
   noteMemo.Height = 200;
   noteMemo.StyledSettings = ssFamily;
   noteMemo.TextSettings.WordWrap = True;
   
   SourceImg = Form1.AddNewImage(Form1,'SourceImg');
   SourceImg.Align = alClient;
   Form1.setImage(SourceImg,'https://clomosy.com/educa/hint.png');
   
   btn1 = Form1.AddNewButton(Form1,'btn1','Upload');
   btn1.StyledSettings = ssFamily;
   btn1.TextSettings.Font.Size = 20;
   btn1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');
   btn1.Align = alBottom;
   Form1.AddNewEvent(btn1,tbeOnClick,'FileStreamExample');
   
   Form1.Run;
 }

See Also