AppendAllText

program AppendAllText;

{$APPTYPE CONSOLE}

{$R *.res}

uses

System.SysUtils, System.IOUtils;

var

s: string;

begin

s:= 'мир' + #10 + 'труд' + #10 + 'май';

TFile.AppendAllText('text.txt', s);

Writeln(TFile.ReadAllText('text.txt'));

Readln;

end.

Copy

unit Unit1;

interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.IOUtils;

type

TForm1 = class(TForm)

btnCopy: TButton;

btnMove: TButton;

btnDelete: TButton;

edSourcePath: TEdit;

edDestinationPath: TEdit;

procedure btnCopyClick(Sender: TObject);

private

{ Private declarations }

procedure operation(Sender: TObject);

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.btnCopyClick(Sender: TObject);

begin

operation(Sender);

end;

procedure TForm1.operation(Sender: TObject);

begin

try

{ Copy file from source file path to destination file path }

if Sender = btnCopy then

TFile.Copy(edSourcePath.Text, edDestinationPath.Text);

{ Move file from source file path to destination file path }

if Sender = btnMove then

TFile.Move(edSourcePath.Text, edDestinationPath.Text);

{ Delete file from source file path }

if Sender = btnDelete then

TFile.Delete(edSourcePath.Text);

except

MessageDlg('Incorrect path', mtError, [mbOK], 0);

Exit;

end;

end;

end.

Create

unit Unit1;

interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.IOUtils;

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

ListBox1: TListBox;

ListBox2: TListBox;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

TPerson = record

Name: string[50];

vorname: string[50];

end;

TComputer = record

Name: string[30];

cpu: string[30];

end;

var

Form1: TForm1;

Person: TPerson;

Computer: TComputer;

Stream: TFileStream;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

try

Stream:= TFile.Create('test.txt');

except

ShowMessage('Ошибка создания файла');

Exit;

end;

Person.Name:= 'Grossenbacher';

Person.vorname:= 'Simon';

Stream.WriteBuffer(Person, SizeOf(TPerson));

Person.Name:= 'Stutz';

Person.vorname:= 'Thomas';

Stream.WriteBuffer(Person, SizeOf(TPerson));

Computer.Name:= 'Delphi';

Computer.cpu:= 'Intel';

Stream.WriteBuffer(Computer, SizeOf(TComputer));

Computer.Name:= 'Win';

Computer.cpu:= 'AMD';

Stream.WriteBuffer(Computer, SizeOf(TComputer));

Stream.Free;

end;

procedure TForm1.Button2Click(Sender: TObject);

var

i: Integer;

begin

try

Stream:= TFile.OpenRead('test.txt');

except

ShowMessage('Ошибка открытия файла');

Exit;

end;

for i:= 2 downto 1 do

begin

Stream.ReadBuffer(Person, SizeOf(TPerson));

ListBox1.Items.Add(Person.vorname + ' ' + Person.Name);

end;

//Einlesen von TComputer

//Read Records TComputer

for i:= 2 downto 1 do

begin

Stream.ReadBuffer(Computer, SizeOf(TComputer));

ListBox2.Items.Add(Computer.Name + ' ' + Computer.cpu);

end;

Stream.Free;

end;

end.


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: