Advertisement
believe_me

Untitled

May 27th, 2022
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 18.41 KB | None | 0 0
  1. Unit SimpleFormUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, System.UITypes;
  8.  
  9. type
  10.   TMatrix = Array of array of Integer;
  11.   TSimpleForm = class(TForm)
  12.     Menu: TMainMenu;
  13.     Instruction: TMenuItem;
  14.     Developer: TMenuItem;
  15.     procedure InstructionClick(Sender: TObject);
  16.     procedure DeveloperClick(Sender: TObject);
  17.     Procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  18.     procedure SetInstructions(); virtual;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
  21.     Procedure FormCloseQueryNope(Sender: TObject; var CanClose: Boolean);
  22.   private
  23.     { Private declarations }
  24.   protected
  25.     Instructions: String;
  26.   public
  27.     { Public declarations }
  28.   end;
  29.  
  30. var
  31.   SimpleForm: TSimpleForm;
  32.  
  33. implementation
  34.  
  35. {$R *.dfm}
  36.  
  37. procedure TSimpleForm.DeveloperClick(Sender: TObject);
  38. begin
  39.     ShowMessage('Ravodin Alexander, group 151002');
  40. end;
  41.  
  42. procedure TSimpleForm.InstructionClick(Sender: TObject);
  43. begin
  44.     ShowMessage(Instructions);
  45. end;
  46.  
  47. Procedure TSimpleForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  48. begin
  49.     CanClose := False;
  50.     if MessageDlg('Are you sure you want to quit?',mtConfirmation, mbOKCancel, 0) = mrOk then
  51.     begin
  52.         CanClose := True;
  53.     end;
  54. end;
  55.  
  56. Procedure TSimpleForm.FormCloseQueryNope(Sender: TObject; var CanClose: Boolean);
  57. Begin
  58.     CanClose := True;
  59. End;
  60.  
  61. procedure TSimpleForm.SetInstructions();
  62. begin
  63.     Instructions := 'F1 - instruction window.' + #13#10 + 'F3 - developer window.'
  64.                     + #13#10 + 'ESCAPE - close window.'+#13#10;
  65. end;
  66.  
  67. procedure TSimpleForm.FormCreate(Sender: TObject);
  68. begin
  69.     SetInstructions;
  70. end;
  71.  
  72. procedure TSimpleForm.FormKeyDown(Sender: TObject; var Key: Word;
  73.   Shift: TShiftState);
  74. begin
  75.     if (Key = VK_ESCAPE) then
  76.         Self.Close;
  77. end;
  78.  
  79.  
  80. end.
  81.  
  82. unit MainForm;
  83.  
  84. interface
  85.  
  86. uses
  87.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  88.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SimpleFormUnit, Vcl.Menus, Vcl.Grids,
  89.   Vcl.StdCtrls, Vcl.Buttons, Vcl.Samples.Spin, Vcl.ValEdit, MatrixForm, System.UITypes;
  90.  
  91. type
  92.    
  93.   TForm7_2 = class(TSimpleForm)
  94.     VertexCountEdit: TSpinEdit;
  95.     ResultButton: TBitBtn;
  96.     IncedenceStringGrid: TStringGrid;
  97.     FileMenu: TMenuItem;
  98.     SaveFile: TMenuItem;
  99.     OpenFile: TMenuItem;
  100.     OpenDialog: TOpenDialog;
  101.     SaveDialog: TSaveDialog;
  102.     InputLabel: TLabel;
  103.     procedure ResultButtonClick(Sender: TObject);
  104.     procedure FormCreate(Sender: TObject);
  105.     procedure VertexCountEditChange(Sender: TObject);
  106.     procedure IncedenceStringGridSetEditText(Sender: TObject; ACol, ARow: Integer;
  107.       const Value: string);
  108.     procedure AnalyseStr(const Value: String; Row: Integer);
  109.     function IsValidStr(const Value: string): Boolean;
  110.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  111.     procedure SaveFileClick(Sender: TObject);
  112.     procedure OpenFileClick(Sender: TObject);
  113.     procedure SetInstructions(); override;
  114.     procedure AnalyseList();
  115.   end;
  116.  
  117. Const
  118.     ENTER_CODE = 13;
  119.    
  120. var
  121.   Form7_2: TForm7_2;
  122.   IncidenceList: PIncidenceList;
  123.  
  124.  
  125. implementation
  126.  
  127. {$R *.dfm}
  128.  
  129. function TForm7_2.IsValidStr(const Value: string): Boolean;
  130. Const
  131.     VALID_ARRAY: array [1..11] of String[1] = ('0','1', '2', '3', '4', '5', '6', '7', '8', '9', ' ');
  132.     MIN_V = 1;
  133.  
  134. function IsNumbCorrect(const Buff: String): Boolean;
  135. Var
  136.     N, MaxV: Integer;
  137. Begin
  138.     MaxV := Self.IncedenceStringGrid.RowCount-1;
  139.     Result := True;
  140.     N := StrToInt(Buff);
  141.     if (N > MaxV) Or (N < MIN_V) then
  142.         Result := False;
  143. End;
  144. Var
  145.     I, J: Integer;
  146.     Find: Boolean;
  147.     Buffer: String[2];
  148. Begin
  149.     Result := True;
  150.     I := 1;
  151.     Buffer := '';
  152.     while (I <= Length(Value)) and (Result) do
  153.     begin
  154.         Find := False;
  155.         J := 1;
  156.         While(J <= Length(VALID_ARRAY)) And (not Find) Do
  157.         begin
  158.             if Value[I] = VALID_ARRAY[J] then
  159.                 Find := True;
  160.             Inc(J);
  161.         end;
  162.         if Value[I] <> ' ' then
  163.             Buffer := Value[I]+Buffer
  164.         else
  165.         begin
  166.             Find := IsNumbCorrect(Buffer);
  167.             Buffer := '';
  168.         end;
  169.         if not Find then
  170.             Result := Find;
  171.         Inc(I);
  172.     end;
  173.     if buffer <> '' then
  174.         Result := IsNumbCorrect(Buffer);
  175. End;
  176.  
  177. procedure TForm7_2.OpenFileClick(Sender: TObject);
  178. Var
  179.     InputFile: TextFile;
  180. begin
  181.     if OpenDialog.Execute then
  182.     Begin
  183.         If FileExists(OpenDialog.FileName) then
  184.         Begin
  185.             if TrySetInputFile(InputFile, OpenDialog.FileName) then
  186.             Begin
  187.                 OpenFromFile(InputFile, Self.IncedenceStringGrid, VertexCountEdit);
  188.                 CloseFile(InputFile);
  189.             End
  190.             Else
  191.                 MessageDlg('File can not be openned.', mtError, [mbOk], 0);
  192.         End;
  193.     End;
  194. end;
  195.  
  196. procedure TForm7_2.SaveFileClick(Sender: TObject);
  197. Var
  198.     OutputFile: TextFile;
  199. begin
  200.     if SaveDialog.Execute then
  201.     Begin
  202.         If FileExists(SaveDialog.FileName) then
  203.         Begin
  204.             if TrySetOutputFile(OutputFile, SaveDialog.FileName) then
  205.             Begin
  206.                 SaveInFile(OutputFile, Self.IncedenceStringGrid);
  207.                 CloseFile(OutputFile);
  208.                 MessageDlg('Successfully saved', mtInformation, [mbOk], 0);
  209.             End
  210.             Else
  211.                 MessageDlg('Something was wrong', mtError, [mbOk], 0);
  212.         End;
  213.     End;
  214. end;
  215.  
  216. procedure TForm7_2.SetInstructions;
  217. Const
  218.     NEW_LINE = #13#10;
  219. begin
  220.     Inherited;
  221.     Instructions := 'This program transfers incidence list into incident matrix.' + NEW_LINE
  222.         + 'Input number of vertices. Then input number of incedent vertices in the 2nd col.' + NEW_LINE
  223.             +'CTRL+S - save matrix in file.' + NEW_LINE + 'CTRL+O - take lists from file.' + NEW_LINE
  224.                 +'To end input and show the result press ENTER and "Show result".';
  225. end;
  226.  
  227. procedure TForm7_2.AnalyseList;
  228. Var
  229.     I: Integer;
  230. begin
  231.     if IncidenceList <> Nil then
  232.         ClearList(IncidenceList);
  233.     for I := 1 to IncedenceStringGrid.RowCount - 1 do
  234.     Begin
  235.         if isValidStr(IncedenceStringGrid.Cells[1, I]) then
  236.             AnalyseStr(IncedenceStringGrid.Cells[1, I], I);
  237.     End;
  238. end;
  239.  
  240. procedure TForm7_2.AnalyseStr(const Value: String; Row: INteger);
  241. Var
  242.     Reader: String[2];
  243.     I, N, ErrorCode: Integer;
  244. procedure AddNumberToList();
  245. Begin
  246.     Val(Reader, N, ErrorCode);
  247.     if ErrorCode = 0 then
  248.         AddToList(IncidenceList, Row, N);
  249. End;
  250. begin
  251.     Reader := '';
  252.     For I := 1 to Length(Value) do
  253.     Begin
  254.         If Value[I] <> ' ' then
  255.             Reader := Reader+Value[I]
  256.         Else
  257.         Begin
  258.             AddNumberToList;
  259.             Reader := '';
  260.         End;
  261.     End;
  262.     AddNumberToList;
  263. end;
  264.  
  265. procedure TForm7_2.ResultButtonClick(Sender: TObject);
  266. begin
  267.      AnalyseList;
  268.      if not Assigned(ResultForm) then
  269.         ResultForm := TResultForm.Create(Self);
  270.      ResultForm.TakeSize(IncedenceStringGrid.RowCount - 1);
  271.      ResultForm.TakeIncedenceList(IncidenceList);
  272.      ResultForm.Show;
  273.  
  274. end;
  275.  
  276. procedure TForm7_2.VertexCountEditChange(Sender: TObject);
  277. Const
  278.     WINDOW_DEFAULT_HEIGHT = 150;
  279. begin
  280.     SetGridSize(1, StrToint(VertexCountEdit.Text), IncedenceStringGrid, 48);
  281.     if IncedenceStringGrid.height > ClientHeight-WINDOW_DEFAULT_HEIGHT then
  282.         ClientHeight := IncedenceStringGrid.height+WINDOW_DEFAULT_HEIGHT;
  283. end;
  284.  
  285. procedure TForm7_2.FormCreate(Sender: TObject);
  286. begin
  287.   inherited;
  288.     IncedenceStringGrid.Cells[0,0] := 'V';
  289.     IncedenceStringGrid.Cells[1,0] := '1';
  290.     IncedenceStringGrid.Cells[0,1] := '1';
  291. end;
  292.  
  293. procedure TForm7_2.FormKeyPress(Sender: TObject; var Key: Char);
  294. begin
  295.   inherited;
  296.    if Key =  Chr(ENTER_CODE) then
  297.    Begin
  298.         ResultButtonClick(Sender);
  299.    End;
  300. end;
  301.  
  302. procedure TForm7_2.IncedenceStringGridSetEditText(Sender: TObject; ACol, ARow: Integer;
  303.   const Value: string);
  304. begin
  305.     if not isValidStr(Value) then
  306.     Begin
  307.         MessageDlg('Wrong data.', mtError, [mbOk], 0);
  308.         (Sender as TStringGrid).Cells[ACol, ARow] := '';
  309.     End;
  310. end;
  311.  
  312. end.
  313.  
  314. unit MatrixForm;
  315.  
  316. interface
  317.  
  318. uses
  319.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  320.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SimpleFormUnit, Vcl.Menus, Vcl.Grids, Vcl.Samples.Spin, System.UITypes,
  321.   Vcl.StdCtrls;
  322.  
  323. type
  324.     PVertex = ^TVertex;
  325.     TVertex = record
  326.         Number: Integer;
  327.         Next: PVertex;
  328.     end;
  329.  
  330.     PIncidenceList = ^TIncidenceList;
  331.     TIncidenceList = Record
  332.         Vertex: Integer;
  333.         Incedent: PVertex;
  334.         Next: PIncidenceList;
  335.     End;
  336.  
  337.     TMatrix = array of array of integer;
  338.  
  339.   TResultForm = class(TSimpleForm)
  340.     AdjacencyGrid: TStringGrid;
  341.     Save: TMenuItem;
  342.     SaveDialog: TSaveDialog;
  343.     ResultLabel: TLabel;
  344.     procedure FormCreate(Sender: TObject);
  345.     procedure TakeSize(N: Integer);
  346.     procedure TakeIncedenceList(IncidenceListPointer: PIncidenceList);
  347.     procedure FullFillGrid(Var Grid: TStringGrid; IncidenceList: PIncidenceList);
  348.     procedure FormShow(Sender: TObject);
  349.     procedure SaveClick(Sender: TObject);
  350.     function receiveIncidentMatrix(var AdjacencyMatrix: TMatrix): TMatrix;
  351.    function receiveAdjacencyMatrix(var IncidenceList: PIncidenceList): TMatrix;
  352.     Private
  353.         GridSize: Integer;
  354.         IncedenceList: PIncidenceList;
  355.   end;
  356.   procedure SetGridSize(const Width, Height: Integer; var StringGrid: TStringGrid; const Offset: integer);
  357.   procedure AddtoList(var List: PIncidenceList; V: Integer; N: Integer);
  358.   Function TrySetOutputFile(var OutputFile: TextFile; const Name: String): Boolean;
  359.   Procedure SaveInFile(var SaveFile: TextFile; const Grid: TStringGrid);
  360.   Function TrySetInputFile(var InputFile: TextFile; const Name: String): Boolean;
  361.   Procedure OpenFromFile(var InputFile: TextFile; var Grid: TStringGrid; var VertexCountEdit: TSpinEdit);
  362.   Procedure ClearList(var IncidenceList: PIncidenceList);
  363. var
  364.   ResultForm: TResultForm;
  365.  
  366. implementation
  367.  
  368. {$R *.dfm}
  369.  
  370. Procedure ClearList(var IncidenceList: PIncidenceList);
  371. Var
  372.     VertexDeleter: PVertex;
  373.     ListDeleter : PIncidenceList;
  374. Begin
  375.     While(IncidenceList <> Nil) do
  376.     Begin
  377.         while IncidenceList^.Incedent <> Nil do
  378.         Begin
  379.             VertexDeleter := IncidenceList^.Incedent;
  380.             IncidenceList^.Incedent := IncidenceList^.Incedent^.Next;
  381.             Dispose(VertexDeleter);
  382.         End;
  383.         ListDeleter := IncidenceList;
  384.         IncidenceList := IncidenceList^.Next;
  385.         Dispose(ListDeleter);
  386.     End;
  387. End;
  388.  
  389. function TrySetOutputFile(var OutputFile: TextFile; const Name: String): Boolean;
  390. Begin
  391.     Result := True;
  392.     AssignFile(OutputFile, Name);
  393.     Try
  394.         Rewrite(OutputFile);
  395.     Except
  396.         Result := False;
  397.     End;
  398. End;
  399.  
  400. Function TrySetInputFile(var InputFile: TextFile; const Name: String): Boolean;
  401. Begin
  402.     Result := True;
  403.     AssignFile(InputFile, Name);
  404.     Try
  405.         Reset(InputFile);
  406.     Except
  407.         Result := False;
  408.     End;
  409. End;
  410.  
  411. procedure OpenFromFile(var InputFile: TextFile; var Grid: TStringGrid; var VertexCountEdit: TSpinEdit);
  412. Var
  413.     i, j, Width: Integer;
  414.     Str: String;
  415.     Buffer: Char;
  416. Begin
  417.     Readln(InputFile, Width);
  418.     VertexCountEdit.Text := IntToStr(Width);
  419.     for i := 1 to Grid.RowCount - 1 do
  420.     Begin
  421.         for j := 0 to 1 do
  422.         Begin
  423.             Buffer := 'f';
  424.             Str := '';
  425.             While (Buffer <> ' ') And (j = 0) do
  426.             Begin
  427.                 Read(InputFile, Buffer);
  428.                 Str := Str + buffer;
  429.             End;
  430.             If (j = 1) Then
  431.             Begin
  432.                 Read(InputFile, Str);
  433.             End;
  434.             Grid.Cells[j, i] := Str;
  435.         End;
  436.         Readln(InputFile);
  437.     End;
  438. End;
  439.  
  440. procedure SaveInFile(var SaveFile: TextFile; const Grid: TStringGrid);
  441. const
  442.     LETTER = 97;
  443. Var
  444.     i, j: Integer;
  445. Begin
  446.     write(SaveFile, '   ');
  447.     for i := 0 to Grid.RowCount do
  448.         write(SaveFile, char(LETTER + i):2, ' ');
  449.     writeln(SaveFile);
  450.     for i := 1 to Grid.RowCount - 1 do
  451.     Begin
  452.         for j := 0 to Grid.ColCount - 1 do
  453.         Begin
  454.             Write(SaveFile, Grid.Cells[j, i]:2);
  455.             Write(SaveFile, ' ');
  456.         End;
  457.         Writeln(SaveFile);
  458.     End;
  459. End;
  460.  
  461. procedure TResultForm.FormCreate(Sender: TObject);
  462. begin
  463.   inherited;
  464.     AdjacencyGrid.Cells[0,0] := 'V';
  465.     AdjacencyGrid.Cells[1,0] := '1';
  466.     AdjacencyGrid.Cells[0,1] := '1';
  467. end;
  468.  
  469. procedure TResultForm.TakeSize(N: Integer);
  470. Begin
  471.     GridSize := N;
  472. End;
  473.  
  474. procedure TResultForm.TakeIncedenceList(IncidenceListPointer: PIncidenceList);
  475. Begin
  476.     IncedenceList := IncidenceListPointer;
  477. End;
  478.  
  479. procedure SetGridSize(const Width, Height: Integer; var StringGrid: TStringGrid; const OFFSET: integer);
  480. Var
  481.     I: Integer;
  482. begin
  483.  
  484.     StringGrid.ColCount := Width + 1;
  485.     StringGrid.RowCount := Height + 1;
  486.  
  487.     for I := 1 to Height do
  488.         StringGrid.Cells[0, I] := IntToStr(I);
  489.     for I := 1 to Width do
  490.         StringGrid.Cells[I, 0] := char(i + OFFSET);
  491.     StringGrid.Width := (Width + 1) * StringGrid.DefaultColWidth + 15;
  492.     StringGrid.Height := (Height + 1) * StringGrid.DefaultRowHeight + 15;
  493. end;
  494.  
  495. procedure AddtoList(var List: PIncidenceList; V: Integer; N: Integer);
  496. Var
  497.     isFind: Boolean;
  498.     Save, Temp: PIncidenceList;
  499.     InTemp: PVertex;
  500. Begin
  501.     isFind := False;
  502.     if List = Nil then
  503.     Begin
  504.         New(List);
  505.         List^.Vertex := V;
  506.         New(List^.Incedent);
  507.         List^.Incedent^.Number := N;
  508.         List^.Next := Nil;
  509.         List^.Incedent^.Next := Nil;
  510.         isFind := True;
  511.     End;
  512.     Temp := List;
  513.     while (not isFind) And (Temp <> Nil) do
  514.     Begin
  515.         if Temp^.Vertex = V then
  516.         Begin
  517.             InTemp := Temp^.Incedent;
  518.             While(InTemp^.Next  <> Nil) do
  519.                 InTemp := InTemp^.Next;
  520.             isFind := True;
  521.             New(InTemp^.Next);
  522.             InTemp := InTemp^.Next;
  523.             InTemp^.Number := N;
  524.             InTemp^.Next := Nil;
  525.         End
  526.         Else
  527.         Begin
  528.             if Temp^.Next = Nil then
  529.                 Save := Temp;
  530.             Temp := Temp^.Next;
  531.         End;
  532.     End;
  533.     if not isFind then
  534.     Begin
  535.         New(Save^.Next);
  536.         Save := Save^.Next;
  537.         Save^.Vertex := V;
  538.         New(Save^.Incedent);
  539.         Save^.Incedent^.Number := N;
  540.         Save.Next := Nil;
  541.         Save^.Incedent^.Next := Nil;
  542.     End;
  543. End;
  544.  
  545. procedure resizeIncidentMatrix(var IncidentMatrix: TMatrix; Col: integer);
  546. var
  547.     i: integer;
  548. begin
  549.     for i := 0 to Col do
  550.         setlength(IncidentMatrix[i], Col);
  551. end;
  552.  
  553. procedure TResultForm.FormShow(Sender: TObject);
  554. begin
  555.     inherited;
  556.     FullFillGrid(AdjacencyGrid, IncedenceList);
  557. end;
  558.  
  559. procedure TResultForm.FullFillGrid(var Grid: TStringGrid; IncidenceList: PIncidenceList);
  560.  
  561. procedure fillGridWithZero();
  562. var
  563.     I, J: Integer;
  564. Begin
  565.     for I := 1 to Grid.RowCount - 1 do
  566.         for J := 1 to Grid.ColCount - 1 do
  567.             Grid.Cells[J, I] := '0';
  568. End;
  569.  
  570. var
  571.     IncidentMatrix, AdjacencyMatrix: TMatrix;
  572.     i, j, col, row: integer;
  573. begin
  574.     fillGridWithZero;
  575.  
  576.     AdjacencyMatrix := receiveAdjacencyMatrix(IncidenceList);
  577.     IncidentMatrix := receiveIncidentMatrix(AdjacencyMatrix);
  578.  
  579.     SetGridSize(length(IncidentMatrix[0]), length(IncidentMatrix), Grid, 96);
  580.     fillGridWithZero();
  581.     if AdjacencyGrid.height > ClientHeight then
  582.         ClientHeight := AdjacencyGrid.height + 30;
  583.     if AdjacencyGrid.Width > ClientWidth then
  584.         ClientWidth := AdjacencyGrid.Width + 30;
  585.  
  586.     col := length(IncidentMatrix[0]);
  587.     row := length(IncidentMatrix);
  588.     for i := 1 to length(IncidentMatrix) do
  589.         for j := 1 to length(IncidentMatrix[0]) do
  590.             Grid.cells[j,i] := intToStr(IncidentMatrix[i-1][j-1]);
  591. end;
  592.  
  593. function TResultForm.receiveIncidentMatrix(var AdjacencyMatrix: TMatrix): TMatrix;
  594. const
  595.     MAX_EDGE_COUNT = 25;
  596. var
  597.     Col, Row, i, j: integer;
  598.     IncidentMatrix: TMatrix;
  599. begin
  600.     Col := 0;
  601.     Row := 0;
  602.     setlength(IncidentMatrix, GridSize, MAX_EDGE_COUNT);
  603.     for i := 0 to high(AdjacencyMatrix) do
  604.     begin
  605.         for j := 0 to high(AdjacencyMatrix) do
  606.         begin;
  607.             if AdjacencyMatrix[i][j] = 1 then
  608.             begin
  609.                 if i = j then
  610.                     IncidentMatrix[j][Col] := 2
  611.                 else
  612.                 begin
  613.                     IncidentMatrix[j][Col] := 1;
  614.                     if (AdjacencyMatrix[j][i] = 1) then
  615.                     begin
  616.                         IncidentMatrix[i][Col] := 1;
  617.                         AdjacencyMatrix[j][i] := 0;
  618.                     end
  619.                     else
  620.                     begin
  621.                         IncidentMatrix[i][Col] := -1;
  622.                         AdjacencyMatrix[j][i] := 0;
  623.                     end;
  624.                 end;
  625.                 inc(Col);
  626.             end;
  627.         end;
  628.     end;
  629.     resizeIncidentMatrix(IncidentMatrix, Col);
  630.     Result := IncidentMatrix;
  631. end;
  632.  
  633. function TResultForm.receiveAdjacencyMatrix(var IncidenceList: PIncidenceList): TMatrix;
  634. var
  635.     Temp: PIncidenceList;
  636.     AdjacencyMatrix: TMatrix;
  637. begin
  638.     setlength(AdjacencyMatrix, GridSize, GridSize);
  639.     Temp := IncidenceList;
  640.     while Temp <> Nil do
  641.     Begin
  642.         while Temp^.Incedent <> Nil do
  643.         Begin
  644.             AdjacencyMatrix[Temp^.Vertex - 1][Temp^.Incedent^.Number - 1] := 1;
  645.             Temp^.Incedent := Temp^.Incedent^.Next;
  646.         End;
  647.         Temp := Temp^.Next;
  648.     End;
  649.     Result := AdjacencyMatrix;
  650. end;
  651.  
  652. procedure TResultForm.SaveClick(Sender: TObject);
  653. Var
  654.     OutputFile: TextFile;
  655. begin
  656.     if SaveDialog.Execute then
  657.     Begin
  658.         If FileExists(SaveDialog.FileName) then
  659.         Begin
  660.             if TrySetOutputFile(OutputFile, SaveDialog.FileName) then
  661.             Begin
  662.                 SaveInFile(OutputFile, Self.AdjacencyGrid);
  663.                 CloseFile(OutputFile);
  664.                 MessageDlg('Data is saved.', mtInformation, [mbOk], 0);
  665.             End
  666.             Else
  667.                 MessageDlg('Error. Data is not saved.', mtError, [mbOk], 0);
  668.         End;
  669.     End;
  670. end;
  671.  
  672. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement