Скачиваний:
19
Добавлен:
01.05.2014
Размер:
4 Кб
Скачать
unit Unit1;

interface

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

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Knopka1: TBitBtn;
Edit1: TEdit;
XPManifest1: TXPManifest;
Shifr: TButton;
MainMemo: TMemo;
Save: TButton;
Label1: TLabel;
procedure FormActivate(Sender: TObject);
procedure Knopka1Click(Sender: TObject);
procedure ShifrClick(Sender: TObject);
procedure SaveClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
i,x,y,z,r,o,a,a2,a3,m,mx,m0: byte;
Text0,Text1: String;
ShifrStolb: array [1..7] of byte = (1,2,3,7,6,5,4); //ключ к столбцам 7 цифр
ShifrStrok: array [1..6] of byte = (1,2,6,3,5,4); //ключ к строкам 6 цифр
Hash: array [1..42] of string;
//---Save-----------------------------------------------------------------------
F:TextFile;
u,g:integer;
so:string;

implementation

{$R *.dfm}
//-----------------------Нумерация StringGrid-----------------------------------
procedure TForm1.FormActivate(Sender: TObject);
begin
for x := 1 to StringGrid1.RowCount-1 do
StringGrid1.Cells[0,x]:= inttostr(StringGrid1.Row+x-1);
for y := 1 to StringGrid1.ColCount-1 do
StringGrid1.Cells[y,0]:= inttostr(StringGrid1.Col+y-1);
Shifr.Enabled:= False;//выкл.кн. шифр
Save.Enabled := False;
end;
// -Проверка символов на количесво и изменение пробелов на другие символы-------
procedure TForm1.Knopka1Click(Sender: TObject);
begin
m :=(StringGrid1.RowCount-1)*(StringGrid1.ColCount-1); m0 :=m-1;
Shifr.Enabled:= True;
Text0 := edit1.Text;
i := length(Text0);
if i > m then ShowMessage ('Вы ввели больше '+inttostr(m)+' символов.Лишние обрезаны!');
if i < m then ShowMessage ('Вы ввели меньше '+inttostr(m)+' символов. Данные сохранены.');
SetLength (Text0,m);
for mx := 0 to m0 do
begin
if Text0[mx] = ' ' then Text0[mx] := #63;//заполнение ? между словами
end ;
for mx := i to m0 do Text0[mx+1] := #63; //заполнение ? лишнего пространства
end;
//------------------ Сортировка по столбцам ------------------------------------
procedure TForm1.ShifrClick(Sender: TObject);
begin
y:=1; x:=1; o:=1; a:=1; a2:=1; a3:=1;
for y := 1 to StringGrid1.RowCount-1 do
begin
for x := 1 to StringGrid1.ColCount-1 do
begin
StringGrid1.Cells[ShifrStolb[x],y]:= Text0[o];
o:=o+1;
end
end;
//---------------------копирование строки в кеш---------------------------------
begin
for y := 1 to StringGrid1.RowCount-1 do
begin
for x := 1 to StringGrid1.ColCount-1 do
begin
Hash[a]:=StringGrid1.Cells[x,y];
a:=a+1;
end ;
end;
//------------------ Сортировка по строкам -------------------------------------
begin
for x := 1 to StringGrid1.ColCount-1 do
begin
for y := 1 to StringGrid1.RowCount-1 do
begin
StringGrid1.Cells[x,ShifrStrok[y]]:= Hash[a2];
a2:=a2+1;
end;
end;
//-----------------------Вывод шифра--------------------------------------------
begin
for y := 1 to StringGrid1.RowCount-1 do
begin
for x := 1 to StringGrid1.ColCount-1 do
begin
Text1:= Text1+(StringGrid1.Cells[x,y]);
a3:=a3+1 ;
end;
end;
MainMemo.Lines.Add(text1);
SetLength(Text1,0);
Shifr.Enabled:= False;
Save.Enabled := True;
end;
end;
end;
end;
//---------------Запись в Файл--------------------------------------------------
procedure TForm1.SaveClick(Sender: TObject);
begin
AssignFile(f,'Result.txt');
Rewrite(f);
for u:=0 to StringGrid1.RowCount-1 do begin
so:='';
For g:=0 to StringGrid1.ColCount-1 do
so:=so+StringGrid1.Cells[g,u]+' ';
writeln(f,so);
writeln(f,'');
end;
CloseFile(f);
Save.Enabled := False;
end;

end.
Соседние файлы в папке Лабораторная работа №12