Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2018.10.21;
Скачать: CL | DM;

Вниз

чтение запись строки из файла   Найти похожие ветки 

 
валя ©   (2016-09-07 13:40) [0]

Как правильно?

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TForm1 = class(TForm)
   Button1: TButton;
   Button2: TButton;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;
 fs: TFileStream;
 str: String;
 Val: Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 fs := TFileStream.Create("1.dat", fmCreate);
 str := "hello";
 Val := Length(str)*sizeof(Char);
 fs.Write(Val, 4);
 fs.Write(str[1], Val);
 fs.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 fs := TFileStream.Create("1.dat", fmOpenRead);
 fs.Read(Val, 4);
 fs.Read(str[1], val);
 fs.Free;

 ShowMessage(str);
end;

end.


 
RWolf ©   (2016-09-07 14:53) [1]

...
 fs.Read(Val, 4);
 SetLength(str, Val);
 if Val<>0 then
   fs.Read(str[1], val)


 
Игорь Шевченко ©   (2016-09-07 17:03) [2]


> Как правильно?


Как в справке



Страницы: 1 вся ветка

Текущий архив: 2018.10.21;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.003 c
2-1472882501
RusSun
2016-09-03 09:01
2018.10.21
Как быстро узнать что в строке одни нули?


11-1267468114
Boguslaw
2010-03-01 21:28
2018.10.21
time difference


1-1359522126
Vasya
2013-01-30 09:02
2018.10.21
Virtual Treeview как скрыть строку


2-1473077853
валя
2016-09-05 15:17
2018.10.21
указатели


2-1472651923
Анна
2016-08-31 16:58
2018.10.21
Удалилась БД