filestorage Files property
Example
Return to Introduction  Previous page  Next page
Applies to
acFileStorage component.  

Declaration
property Files: TStoredFiles; { Successor of TList. Contains the list of TStoredFile objects }  

Description
The Files property is the List, which contains all currently stored files. Every item of this list is the file uploaded onto your form at design-time. All files in this list are TStoredFile objects.  
 
If you would like to access stored file at run-time directly from memory you may use following example:  
 
var  
  StoredFile: TStoredFile;  
  DataStream: TMemoryStream;  
begin  
  StoredFile := FileStorage1.Files[1];  
  DataStream := StoredFile.Data; // Data: TMemoryStream  

tip Another example (demonstrates how to retrieve the content of text file to Memo control):
begin  
  TStoredFile(acFileStorage1.Files[0]).Data.Position := 1; // Since Data is the stream we must reset its position  
  Memo1.Lines.LoadFromStream(TStoredFile(acFileStorage1.Files[0]).Data);  
end;  

tip And yet another example (demonstrates how to retrieve the stored file as string):
procedure TForm1.Button1Click(Sender: TObject);  
var  
  StoredFile: TStoredFile;  
  St: String;  
begin  
  StoredFile := acFileStorage1.Files[0]; // first file from FileStorage  
 
  SetLength(St, StoredFile.Data.Size); // set the length of string (StoredFile.Data is the TMemoryStream)  
  Move(StoredFile.Data.Memory^, St[1], StoredFile.Data.Size);  
 
  // and finally we can put the retreived string to Memo control  
  Memo1.Text := St;  
end;  

See also
Count and DataSize properties;  
Extract method.