unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, Grids, ImgList, XPMan, ComCtrls, ToolWin; type MasInt = array [0..1000] of integer; TForm1 = class(TForm) MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; N9: TMenuItem; N10: TMenuItem; N11: TMenuItem; N12: TMenuItem; N13: TMenuItem; N14: TMenuItem; N15: TMenuItem; N16: TMenuItem; DataGrid: TStringGrid; ImageList1: TImageList; SaveDialog1: TSaveDialog; OpenDialog1: TOpenDialog; XPManifest1: TXPManifest; StatusBar1: TStatusBar; ToolBar1: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; ToolButton4: TToolButton; ToolButton5: TToolButton; ToolButton6: TToolButton; ToolButton7: TToolButton; ToolButton8: TToolButton; ToolButton9: TToolButton; ToolButton10: TToolButton; ToolButton11: TToolButton; ToolButton12: TToolButton; ToolButton13: TToolButton; procedure DataGridSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure DataGridKeyPress(Sender: TObject; var Key: Char); procedure N10Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure N4Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure N7Click(Sender: TObject); procedure N6Click(Sender: TObject); procedure N13Click(Sender: TObject); procedure N11Click(Sender: TObject); procedure RecRas(glubina:integer; manum:masint); procedure DataGridSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); procedure N14Click(Sender: TObject); procedure N16Click(Sender: TObject); private { Private declarations } public cancel: boolean; knp: integer; { Public declarations } end; var Form1: TForm1; masras: array [0..1000,0..1000] of integer; Row, Col, i, minras, knp: integer; change: boolean; put: string; manum: masint; implementation uses Unit2, Unit3; {$R *.dfm} procedure TForm1.DataGridSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin if (((ACol>0) and (ARow>0)) or (n12.Checked)) and (ACol<>ARow) then begin DataGrid.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing]; end else begin DataGrid.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect]; end; Col:=ACol; Row:=ARow; end; procedure TForm1.DataGridKeyPress(Sender: TObject; var Key: Char); begin if not ((Col=0) or (Row=0)) then if not(Key in['1','2','3','4','5','6','7','8','9','0',chr(8)]) then Key:=chr(0); end; procedure TForm1.N10Click(Sender: TObject); begin form1.Close; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin if change then begin Action:=caNone; if MessageDlg('Хотели бы Вы сохранить данные перед выходом ?',mtConfirmation,[mbNo,mbYes,mbCancel],0)=mrNo then Action:=caFree; end; end; procedure TForm1.FormCreate(Sender: TObject); begin change:=false; cancel:=false; Form2:=TForm2.Create(Form1); Form2.ShowModal; Form2.Free; DataGrid.RowCount:=knp+1; DataGrid.ColCount:=knp+1; for i:=1 to knp do begin DataGrid.Cells[0,i]:='Город №'+IntToStr(i); DataGrid.Cells[i,0]:='Город №'+IntToStr(i); DataGrid.Cells[i,i]:='0'; end; DataGrid.Cells[0,0]:='Города'; end; procedure TForm1.N4Click(Sender: TObject); begin cancel:=false; Form2:=TForm2.Create(Form1); Form2.ShowModal; Form2.Free; if not cancel then begin if change then begin case MessageDlg('Хотели бы Вы сохранить данные ?',mtConfirmation,[mbNo,mbYes,mbCancel],0) of mrCancel:begin knp:=DataGrid.RowCount-1; exit; end; mrYes: form1.N7Click(Sender); end; end; DataGrid.RowCount:=0; DataGrid.ColCount:=0; DataGrid.RowCount:=knp+1; DataGrid.ColCount:=knp+1; for i:=1 to knp do begin DataGrid.Cells[0,i]:='Город №'+IntToStr(i); DataGrid.Cells[i,0]:='Город №'+IntToStr(i); DataGrid.Cells[i,i]:='0'; end; DataGrid.Cells[0,0]:='Города'; end; end; procedure TForm1.FormShow(Sender: TObject); begin if cancel then form1.Close; end; procedure TForm1.N7Click(Sender: TObject); var f: textfile; x, y: integer; begin if SaveDialog1.Execute then begin assignfile(f,SaveDialog1.FileName+'.dzk'); rewrite(f); writeln(f, knp); for X := 0 to knp do for y := 0 to knp do writeln(F, DataGrid.cells[x, y]); closefile(f); change:=false; end; end; procedure TForm1.N6Click(Sender: TObject); var f: textfile; tempstr: string; x, y : integer; begin if OpenDialog1.Execute then begin assignfile(f, OpenDialog1.FileName); reset(f); readln(f, knp); DataGrid.colcount :=knp+1; DataGrid.rowcount :=knp+1; for X := 0 to knp do for y := 0 to knp do begin readln(F, tempstr); DataGrid.cells[x, y] := tempstr; end; closefile(f); form1.Width:=120+knp*60; if form1.width>screen.Width then form1.width:=screen.Width; form1.Height:=190+knp*20; if form1.Height>screen.Height-40 then form1.Height:=screen.Height-40; form1.left:=round((screen.Width-form1.width)/2); form1.top:=round((screen.Height-form1.height-40)/2); change:=false; end; end; procedure TForm1.N13Click(Sender: TObject); var x,y: integer; begin for x:=2 to knp do for y:=1 to x-1 do DataGrid.Cells[y,x]:=DataGrid.Cells[x,y]; end; procedure TForm1.RecRas(glubina:integer; manum:masint); var i,y,ras: integer; mojno: boolean; begin if glubina