unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button3: TButton;
Panel1: TPanel;
Edit1: TEdit;
Button4: TButton;
Label1: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
StringGrid2: TStringGrid;
Button5: TButton;
Image1: TImage;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
max1,max2,Coll,Roww:integer;
qw:boolean;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8]) then key:=#0;
end;
procedure TForm1.Button4Click(Sender: TObject);
var i,j,m:integer;
begin
stringgrid1.RowCount:=strtoint(edit1.text)+1;
stringgrid1.colCount:=strtoint(edit1.text)+1;
{ for i:=1 to stringgrid1.colCount-1 do
for j:=1 to stringgrid1.rowCount-1 do
if i=j then stringgrid1.cells[i,j]:='0';}
m:=StringGrid1.RowCount;
with StringGrid1 do
begin
j:=1;
m:=m+65;
for i:=65 to m do
begin
cells[j,0]:=chr(i);
inc(j);
end;
end;
m:=StringGrid1.colCount;
with form1.StringGrid1 do
begin
j:=1;
m:=m+65;
for i:=65 to m do
begin
cells[0,j]:=chr(i);
inc(j);
end;
end;
memo1.Text:='Матрица смежности готова для заполнения';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.StringGrid2KeyPress(Sender: TObject; var Key: Char);
begin
with TStringGrid(Sender) do
if (Length(Cells[Col,Row])=1)and (not(key in [#8])) then key:=#0;
end;
procedure TForm1.StringGrid2SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
{ with TStringGrid(Sender) do
if (Length(Cells[Col,Row])=1) then Cells[Col,Row]:=''; }
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
with TStringGrid(Sender) do
if (Length(Cells[Col,Row])=1)and (not(key in ['1'..'9',#8])) then key:=#0;
end;
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
begin
stringgrid1.Cells[arow,acol]:=stringgrid1.Cells[acol,arow];
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
begin
with StringGrid1 do
for i:=1 to colCount-1 do
for j:=1 to rowCount-1 do
cells[i,j]:='';
with StringGrid2 do
for i:=1 to colCount-1 do
for j:=1 to rowCount-1 do
cells[i,j]:='';
memo1.Text:='Таблицы очищены!';
qw:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
for i:=1 to stringgrid1.colCount-1 do
for j:=1 to stringgrid1.rowCount-1 do
if stringgrid1.cells[i,j]='' then stringgrid1.cells[i,j]:='0';
end;
procedure TForm1.Button5Click(Sender: TObject);
var i,j,k,m,p,kk:integer;
qw:boolean;
begin
for i:=1 to stringgrid1.ColCount-1 do
for j:=1 to stringgrid1.rowCount-1 do
if stringgrid1.cells[i,j]='' then qw:=true;
if qw=true then showmessage('Матрица не заполнена!') else
begin
k:=0;
stringgrid2.colCount:=stringgrid1.RowCount;
for i:=1 to stringgrid1.colCount-1 do
for j:=1 to stringgrid1.rowCount-1 do
if stringgrid1.cells[i,j]<>'0' then inc(k);
k:=k div 2;
stringgrid2.rowCount:=k+1;
m:=form1.StringGrid2.colCount;
with form1.StringGrid2 do
begin
for i:=1 to rowcount-1 do
cells[0,i]:=inttostr(i);
end;
with form1.StringGrid2 do
begin
j:=1;
m:=m+65;
for i:=65 to m do
begin
cells[j,0]:=chr(i);
inc(j);
end;
end;
kk:=1;
p:=2;
for j:=1 to stringgrid1.rowcount-1 do
for i:=p to stringgrid1.ColCount-1 do
if stringgrid1.Cells[i,j]='1' then
begin
stringgrid2.Cells[i,kk]:='1';
stringgrid2.Cells[J,kk]:='1';
inc(kk);
inc(p);
end;
for i:=1 to stringgrid2.colCount-1 do
for j:=1 to stringgrid2.rowCount-1 do
if stringgrid2.cells[i,j]='' then stringgrid2.cells[i,j]:='0';
memo1.Text:='Матрица инцидентности успешно создана';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
form2.visible:=false;
memo1.Clear;
memo1.Text:='Введите количество вершин графа';
qw:=false;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form2.visible:=true;
end;
end.
// cyberforum.ru/delphi-beginners/thread1210553.html