Урок на Делфи 75. База данных из txt файлов


задание на delphi. База даных на базе txt файлов

unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Data.DB,
Vcl.DBGrids, Data.Win.ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Label1: TLabel;
StringGrid1: TStringGrid;
procedure Button3Click(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
k_x,k_y:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
stolb:TStringList;
i,j:integer;
begin
for j := 1 to 4 do
begin
stolb:=TStringList.Create;
for I := 0 to StringGrid1.RowCount do
begin
stolb.Add(StringGrid1.Cells[j,i]);
end;
stolb.SaveToFile('stolb'+IntToStr(j)+'.txt');
FreeAndNil(stolb);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
stolb:TStringList;
i,j:integer;
begin
for j := 1 to 4 do
begin
stolb:=TStringList.Create;
stolb.LoadFromFile('stolb'+IntToStr(j)+'.txt');
for I := 0 to StringGrid1.RowCount do
begin
StringGrid1.Cells[j,i]:=stolb[i];
end;
FreeAndNil(stolb);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
StringGrid1.Cells[k_x,k_y]:=Edit1.Text;
Edit1.Clear;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
StringGrid1.DefaultColWidth:=145;
StringGrid1.RowCount:=50;
StringGrid1.ColCount:=5;
//StringGrid1.Options.goEditing
StringGrid1.Cells[0,0]:='';
StringGrid1.Cells[1,0]:='';
StringGrid1.Cells[2,0]:=' ';
StringGrid1.Cells[3,0]:='';
StringGrid1.Cells[4,0]:='-';
for I := 0 to StringGrid1.RowCount do
begin
StringGrid1.Cells[0,i]:=IntToStr(i);
end;
end;
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
Edit1.SetFocus;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
k_x:=ACol;
k_y:=ARow;
Label1.Caption:=IntToStr(k_x)+' '+IntToStr(k_y);
end;
end.



Скачать