From Clomosy Docs
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.
Clomosy.FileToStream(AFileName:string):TclMemoryStream;
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).
- TRObject Syntax
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;
}
- Base Syntax
var
Form1 : TCLForm;
loadImageButton : TClProButton;
Img1 : TCLImage;
memoryStream : TCLMemoryStream;
procedure loadImageButtonClick
var
MyFileStr : String;
begin
MyFileStr := clPathCombine('apple.png', Clomosy.AppFilesPath);
if clFileExists('apple.png', Clomosy.AppFilesPath) then
begin
memoryStream := Clomosy.FileToStream(MyFileStr);
Img1.Bitmap.LoadFromStream(memoryStream);
//Img1.Bitmap.LoadFromFile(MyFileStr);
ShowMessage('Image Uploaded.');
end
else
ShowMessage('No File');
end;
//------ Main Code -------------
begin
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;
end;