From Clomosy Docs
No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
FileToStream | <div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert"> | ||
function Clomosy.FileToStream(AFileName:string):TclMemoryStream; | |||
</div> | |||
FileToStream refers to the process of loading the contents of a file into a stream, specifically a TclMemoryStream. This involves reading the contents of a file and transferring them into a TclMemoryStream instance in memory. This method enables representing the file contents in memory or another data source, allowing for more flexible operations on the content.<br> | |||
<b>Example</b><br> | |||
In the example below, when the application starts, an image is added to the project files using the AddAssetFromUrl function. Then, when a button is clicked, this image is converted to a TclMemoryStream object using the FileToStream function, which returns a TclMemoryStream. This object is then assigned to an image component (Img1).<br> | |||
<pre> | |||
var | var | ||
Form1 : TCLForm; | Form1 : TCLForm; | ||
| Line 62: | Line 16: | ||
memoryStream : TCLMemoryStream; | memoryStream : TCLMemoryStream; | ||
void loadImageButtonClick | |||
var | var | ||
MyFileStr : String; | MyFileStr : String; | ||
{ | |||
MyFileStr | MyFileStr = clPathCombine('apple.png', Clomosy.AppFilesPath); | ||
if clFileExists('apple.png', Clomosy.AppFilesPath) | if clFileExists('apple.png', Clomosy.AppFilesPath) | ||
{ | |||
memoryStream | memoryStream = Clomosy.FileToStream(MyFileStr); | ||
Img1.Bitmap.LoadFromStream(memoryStream); | Img1.Bitmap.LoadFromStream(memoryStream); | ||
//Img1.Bitmap.LoadFromFile(MyFileStr); | //Img1.Bitmap.LoadFromFile(MyFileStr); | ||
ShowMessage('Image Uploaded.'); | ShowMessage('Image Uploaded.'); | ||
} | |||
else | else | ||
ShowMessage('No File'); | ShowMessage('No File'); | ||
} | |||
//------ Main Code ------------- | //------ Main Code ------------- | ||
{ | |||
Form1 | Form1 = TCLForm.Create(Self); | ||
Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png'); | Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png'); | ||
MemoryStream | MemoryStream = TclMemoryStream.Create; | ||
Img1 | Img1 = Form1.AddNewImage(Form1,'Img1'); | ||
Img1.Width | Img1.Width = 100; | ||
Img1.Height | Img1.Height = 100; | ||
loadImageButton | loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Upload Image'); | ||
loadImageButton.Align | loadImageButton.Align = alMostBottom; | ||
loadImageButton.Margins.Top | loadImageButton.Margins.Top = 20; | ||
loadImageButton.clProSettings.FontSize | loadImageButton.clProSettings.FontSize = 16; | ||
loadImageButton.clProSettings.FontColor | loadImageButton.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff'); | ||
loadImageButton.clProSettings.BackgroundColor | loadImageButton.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#6966ff'); | ||
loadImageButton.clProSettings.RoundHeight | loadImageButton.clProSettings.RoundHeight = 10; | ||
loadImageButton.clProSettings.RoundHeight | loadImageButton.clProSettings.RoundHeight = 10; | ||
loadImageButton.SetclProSettings(loadImageButton.clProSettings); | loadImageButton.SetclProSettings(loadImageButton.clProSettings); | ||
Form1.AddNewEvent(loadImageButton,tbeOnClick,'loadImageButtonClick'); | Form1.AddNewEvent(loadImageButton,tbeOnClick,'loadImageButtonClick'); | ||
Form1.Run; | Form1.Run; | ||
} | |||
</pre> | |||
<h2> See Also </h2> | |||
* [[Clomosy_Class#File_and_Stream_Handling | File and Stream Handling]] | |||
{{#seo:|title=FileToStream in Clomosy - Clomosy Docs}} | |||
{{#seo:|description=Learn about FileToStream in Clomosy. A guide to converting files into streams for efficient data handling in your mobile apps.}} | |||
Latest revision as of 12:51, 24 December 2024
function Clomosy.FileToStream(AFileName:string):TclMemoryStream;
FileToStream refers to the process of loading the contents of a file into a stream, specifically a TclMemoryStream. This involves reading the contents of a file and transferring them into a TclMemoryStream instance in memory. This method enables representing the file contents in memory or another data source, allowing for more flexible operations on the content.
Example
In the example below, when the application starts, an image is added to the project files using the AddAssetFromUrl function. Then, when a button is clicked, this image is converted to a TclMemoryStream object using the FileToStream function, which returns a TclMemoryStream. This object is then assigned to an image component (Img1).
var
Form1 : TCLForm;
loadImageButton : TClProButton;
Img1 : TCLImage;
memoryStream : TCLMemoryStream;
void loadImageButtonClick
var
MyFileStr : String;
{
MyFileStr = clPathCombine('apple.png', Clomosy.AppFilesPath);
if clFileExists('apple.png', Clomosy.AppFilesPath)
{
memoryStream = Clomosy.FileToStream(MyFileStr);
Img1.Bitmap.LoadFromStream(memoryStream);
//Img1.Bitmap.LoadFromFile(MyFileStr);
ShowMessage('Image Uploaded.');
}
else
ShowMessage('No File');
}
//------ Main Code -------------
{
Form1 = TCLForm.Create(Self);
Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png');
MemoryStream = TclMemoryStream.Create;
Img1 = Form1.AddNewImage(Form1,'Img1');
Img1.Width = 100;
Img1.Height = 100;
loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Upload Image');
loadImageButton.Align = alMostBottom;
loadImageButton.Margins.Top = 20;
loadImageButton.clProSettings.FontSize = 16;
loadImageButton.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
loadImageButton.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#6966ff');
loadImageButton.clProSettings.RoundHeight = 10;
loadImageButton.clProSettings.RoundHeight = 10;
loadImageButton.SetclProSettings(loadImageButton.clProSettings);
Form1.AddNewEvent(loadImageButton,tbeOnClick,'loadImageButtonClick');
Form1.Run;
}