SHARE
TWEET

Untitled

a guest Aug 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Utils;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure OnCreate(Sender: TObject);
  12.  
  13.     private
  14.       selectedFile: string;
  15.       FileIntoString: string;
  16.   end;
  17.  
  18. var
  19.   Form1: TForm1;
  20.  
  21. implementation
  22. {$R *.dfm}
  23.  
  24. procedure TForm1.OnCreate(Sender: TObject);
  25.   function fileToString(fileName: String): String;
  26.   var
  27.     FileStream: TFileStream;
  28.     Reader: TReader;
  29.     myStringBuilder: TStringBuilder;
  30.  
  31.   begin
  32.     FileStream := TFileStream.Create(fileName, fmOpenRead);
  33.     Reader := TReader.Create(FileStream, $FF);
  34.  
  35.     myStringBuilder := TStringBuilder.Create;
  36.     Reader.ReadListBegin;                       //I get 'Invalid property Value' error
  37.                                                 //in this line raised from the Reader object
  38.  
  39.     while not Reader.EndOfList do
  40.       myStringBuilder.Append(Reader.ReadString);
  41.  
  42.     Reader.ReadListEnd;
  43.     Result := myStringBuilder.ToString;
  44.  
  45.     Reader.Destroy;
  46.     FileStream.Destroy;
  47.   end;
  48.  
  49. var
  50.   dlg: TOpenDialog;
  51. begin
  52.  
  53. //SELECT FILE
  54.   selectedFile := '';
  55.   dlg := TOpenDialog.Create(nil);
  56.   try
  57.     dlg.InitialDir := '.';
  58.     dlg.Filter := 'All files (*.*)|*.*';
  59.     if dlg.Execute(Handle) then
  60.       selectedFile := dlg.FileName;
  61.   finally
  62.     dlg.Free;
  63.   end;
  64.  
  65. //CONVERT INTO STRING
  66. if selectedFile <> '' then
  67.   FileIntoString := fileToString(selectedFile);
  68. end;
  69. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top