SHARE
TWEET

Untitled

a guest Aug 19th, 2019 54 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.   end;
  16.  
  17. var
  18.   Form1: TForm1;
  19.  
  20. implementation
  21. {$R *.dfm}
  22.  
  23. procedure TForm1.OnCreate(Sender: TObject);
  24.   function ReadFileContent(fileName: String): String;
  25.   var
  26.     FileStream: TFileStream;
  27.     Reader: TReader;
  28.     tByte :byte;
  29.  
  30.   begin
  31.  
  32.     FileStream := TFileStream.Create(fileName, fmOpenRead);
  33.     Reader := TReader.Create(FileStream, $FF);
  34.  
  35.     Reader.ReadListBegin;           //I get 'Invalid property Value' error
  36.                                     //in this line raised from the Reader object
  37.  
  38.     while not Reader.EndOfList do
  39.     begin
  40.       Reader.ReadVar(tByte, 1);
  41.     end;
  42.  
  43.     Reader.ReadListEnd;
  44.  
  45.     Reader.Destroy;
  46.     FileStream.Destroy;
  47.   end;
  48.  
  49. var
  50.   dlg: TOpenDialog;
  51. begin
  52.   selectedFile := '';
  53.   dlg := TOpenDialog.Create(nil);
  54.   try
  55.     dlg.InitialDir := '.';
  56.     dlg.Filter := 'All files (*.*)|*.*';
  57.     if dlg.Execute(Handle) then
  58.       selectedFile := dlg.FileName;
  59.   finally
  60.     dlg.Free;
  61. end;
  62.  
  63. if selectedFile <> '' then
  64.   ReadFileContent(selectedFile);
  65. end;
  66. end.
  67.      
  68. MyStringVariable := TFile.ReadAllText('C:myfile.txt');
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