Подскажите плиз, при чтении из файла через TmemoryStream выходит access violation.
| Код | unit TEST1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ToolWin, ComCtrls, ActnMan, ActnCtrls, Grids;
const MaxElements = 10;
type TForm1 = class(TForm) StringGrid2: TStringGrid; LoadButton1: TButton; procedure LoadButton1Click(Sender: TObject);
private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.LoadButton1Click(Sender: TObject); var p2: TMemoryStream; LE, i:integer; k: array[1..MaxElements] of string; W: string; begin p2:= TMemoryStream.Create; try p2.LoadfromFile('D:\тест\file34.txt'); // загружаю данные из файла в буфер p2.position:=0; p2.ReadBuffer(PChar(W)^, p2.size); // читаю данные из буфера LE := Pos(#13#10, W); i:=0; while LE> 0 do begin inc(i); k[i+low(k)-1] := Copy(W, 1, LE - 1); delete (W,1,LE+1); LE := Pos(#13#10, W); end; finally p2.Free; end; for i := 1 to MaxElements do StringGrid2.Cells[1, I] := (k[i]); end; end.
|
|