Advertisement
gguuppyy

форма32

Mar 10th, 2024 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.46 KB | None | 0 0
  1. Unit form23;
  2.  
  3. Interface
  4.  
  5. Uses
  6. Math,
  7. Vcl.ExtDlgs,
  8. Vcl.Dialogs,
  9. Vcl.Menus,
  10. Vcl.StdCtrls,
  11. Vcl.Controls,
  12. Winapi.Windows,
  13. Winapi.Messages,
  14. System.SysUtils,
  15. System.Variants,
  16. System.Classes,
  17. Vcl.Graphics,
  18. Vcl.Forms,
  19. Unit23_1,
  20. Unit23_2,
  21. Vcl.ComCtrls,
  22. Vcl.Grids;
  23.  
  24. Type
  25. TErrorCode = (EcCorrect, EcInvalid_Value, EcInvalid_Range, EcNot_Readable, EcNot_Writeable, EcIncorrect_Amount_lines);
  26. Type
  27. TArr = Array Of Array Of Array Of Integer;
  28. TMainForm = Class(TForm)
  29. MainMenu: TMainMenu;
  30. FileMenu: TMenuItem;
  31. OpenMenu: TMenuItem;
  32. SaveMenu: TMenuItem;
  33. ExitMenu: TMenuItem;
  34. InstructionMenu: TMenuItem;
  35. DeveloperMenu: TMenuItem;
  36. TaskLabel: TLabel;
  37. NEdit: TEdit;
  38. ResultButton: TButton;
  39. ResultEdit: TEdit;
  40. MyOpenTextFileDialog: TOpenTextFileDialog;
  41. MySaveTextFileDialog: TSaveTextFileDialog;
  42. RLabel: TLabel;
  43. XGrid: TStringGrid;
  44. Label1: TLabel;
  45. PopupMenu1: TPopupMenu;
  46. Label2: TLabel;
  47. MEdit: TEdit;
  48. KEdit: TEdit;
  49. Label3: TLabel;
  50. Procedure NEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  51. Procedure InstructionMenuClick(Sender: TObject);
  52. Procedure DeveloperMenuClick(Sender: TObject);
  53. Procedure OpenMenuClick(Sender: TObject);
  54. Procedure SaveMenuClick(Sender: TObject);
  55. Procedure ResultButtonClick(Sender: TObject);
  56. Procedure ExitMenuClick(Sender: TObject);
  57. Procedure CalcResult(Sender: TObject);
  58. Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
  59. Function CheckInputFields(Sender: TObject; CurEdit: TEdit; CurStringGrid: TStringGrid): Boolean;
  60. Procedure FileMenuClick(Sender: TObject);
  61. Procedure CheckEdit(Sender: TObject; Var Key: Char; CurEdit: TEdit);
  62. Procedure SelectEdit(Sender: TObject; Var Key: Word);
  63. Procedure FormCreate(Sender: TObject);
  64.  
  65. function CheckCells(CurStringGrid: TStringGrid): Boolean;
  66. Procedure NEditKeyPress(Sender: TObject; Var Key: Char);
  67. Procedure XGridSetEditText(Sender: TObject; ACol, ARow: Integer; Const Value: String);
  68. Procedure NEditChange(Sender: TObject);
  69. Procedure GridCheck(Sender: TObject);
  70. Procedure XGridKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  71. Procedure SelectEdit2 (Sender: TObject; Var Key: Word; CurEdit:TEdit);
  72. Procedure MEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  73. procedure MEditKeyPress(Sender: TObject; var Key: Char);
  74. procedure MEditChange(Sender: TObject);
  75. procedure KEditChange(Sender: TObject);
  76. procedure KEditKeyPress(Sender: TObject; var Key: Char);
  77. procedure KEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  78. Function EnterArr():TArr;
  79. procedure ColorizeColumn(StringGrid: TStringGrid; ColumnIndex: Integer; Color: TColor);
  80. procedure XGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
  81. State: TGridDrawState);
  82. Private
  83. { Private declarations }
  84. Public
  85. { Public declarations }
  86. End;
  87.  
  88. Const
  89. ERRORS: Array [TErrorCode] Of String = ('', 'Некорректный тип данных внутри файла!', 'Значения не попадают в диапазон!',
  90. 'Файл закрыт для чтения!', 'Файл закрыт для записи!', 'Неверное количество данных в файле');
  91. BACKSPACE = #8;
  92. NONE = #0;
  93. DIGITS = ['0' .. '9'];
  94. MAX_N = 10;
  95. MIN_N = 3;
  96. MAX_X = 1000;
  97. MIN_X = -1000;
  98.  
  99. Var
  100. MainForm: TMainForm;
  101.  
  102. Implementation
  103.  
  104. {$R *.dfm}
  105.  
  106. Function IsAbleToReading(Var F: TextFile): TErrorCode;
  107. Var
  108. Error: TErrorCode;
  109. Begin
  110. Error := EcCorrect;
  111. Try
  112. Reset(F);
  113. CloseFile(F);
  114. Except
  115. Error := EcNot_Readable;
  116. End;
  117. IsAbleToReading := Error;
  118. End;
  119.  
  120. Function FindChar(MyText: String; MyChar: Char): Boolean;
  121. Var
  122. N, I, Counter: Integer;
  123. Begin
  124. N := Length(MyText);
  125. Counter := 0;
  126. For I := 1 To N Do
  127. If MyText[I] = MyChar Then
  128. Inc(Counter);
  129. If Counter = 0 Then
  130. FindChar := False
  131. Else
  132. FindChar := True;
  133. End;
  134.  
  135. Function CheckUserArea(Num: Integer; Const MAX, MIN: Integer): Boolean;
  136.  
  137. Var
  138. IsCorrect: Boolean;
  139. Begin
  140. If (Num < 2) Or (Num > 90) Then
  141. Begin
  142. IsCorrect := False;
  143. End
  144. Else
  145. IsCorrect := True;
  146. CheckUserArea := IsCorrect;
  147. End;
  148.  
  149. Function CheckXArea(Num: Double; Const MAX, MIN: Real): Boolean;
  150.  
  151. Var
  152. IsCorrect: Boolean;
  153. Begin
  154. If (Num < MIN) Or (Num > MAX) Then
  155. Begin
  156. IsCorrect := False;
  157. End
  158. Else
  159. IsCorrect := True;
  160. CheckXArea := IsCorrect;
  161. End;
  162.  
  163. Function CheckFileData(Var F: TextFile; N, M,k1: Integer; var Error: TErrorCode):TErrorCode;
  164. Var
  165. KLine: String;
  166. K :Real;
  167. numbers: TArray<string>;
  168. CountN, CountM, I: Integer;
  169. Begin
  170. I := 0;
  171. CountM := 0;
  172. While (Error= EcCorrect)And Not EOF(F) Do
  173. Begin
  174.  
  175. Try
  176. Read(F, KLine);
  177. numbers := KLine.Split([' ']);
  178. Except
  179. Error := EcInvalid_Value;
  180. End;
  181. If (Error= EcCorrect) And (Length(numbers) <> N*K1) Then
  182. Begin
  183. Error := EcIncorrect_Amount_lines;
  184. End;
  185. I:=0;
  186. While (Error= EcCorrect) And (I<(Length(numbers))) Do
  187. Begin
  188. Try
  189. K:= StrToFloat(numbers[I]);
  190. Except
  191. Error := EcInvalid_Value;
  192. End;
  193. Inc(I);
  194. If (Error= EcCorrect)And Not(CheckXArea(K, MAX_X, MIN_X)) Then
  195. Error := EcInvalid_Range;
  196. End;
  197.  
  198. Inc(CountM);
  199. Readln(F);
  200. End;
  201. If(Error= EcCorrect)And( CountM <> M) Then
  202. Begin
  203. Error := EcIncorrect_Amount_lines;
  204. End;
  205. CloseFile(F);
  206. CheckFileData := Error;
  207. End;
  208.  
  209. Function CheckFileData1(Var F: TextFile): TErrorCode;
  210. Var
  211. FLine: String;
  212. I, N,M,J,k1: Integer;
  213. K, S: Double;
  214. Error: TErrorCode;
  215. Begin
  216. Error := EcCorrect;
  217. Reset(F);
  218.  
  219. For I := 1 To 3 Do
  220. Begin
  221. Readln(F, FLine);
  222. Try
  223. Begin
  224. If I = 1 Then
  225. M := StrToInt(FLine)
  226. Else
  227. If I = 2 Then
  228.  
  229. N := StrToInt(FLine)
  230. Else
  231. K1 := StrToInt(FLine)
  232. End;
  233. Except
  234. Error := EcInvalid_Value;
  235. End;
  236.  
  237. If (Error = EcCorrect) And Not(CheckUserArea(StrToInt(FLine), MAX_N, MIN_N)) Then
  238. Error := EcInvalid_Range;
  239.  
  240. End;
  241. if Error = EcCorrect then
  242. Error:=CheckFileData( F, N, M,k1,Error);
  243. CheckFileData1:= Error;
  244. End;
  245.  
  246. Procedure TMainForm.DeveloperMenuClick(Sender: TObject);
  247. Var
  248. DeveloperForm: TDeveloperForm;
  249. Begin
  250. DeveloperForm := TDeveloperForm.Create(Self);
  251. DeveloperForm.ShowModal;
  252. DeveloperForm.Free;
  253. End;
  254.  
  255. Procedure TMainForm.InstructionMenuClick(Sender: TObject);
  256. Var
  257. InstructionForm: TInstructionForm;
  258. Begin
  259.  
  260. InstructionForm := TInstructionForm.Create(Self);
  261. InstructionForm.ShowModal;
  262. InstructionForm.Free;
  263. End;
  264.  
  265. procedure TMainForm.KEditChange(Sender: TObject);
  266. Var
  267. I, L, K:Integer;
  268. Begin
  269. If (KEdit.Text = '') Then
  270. Begin
  271. for I := 0 to XGrid.ColCount-1 do
  272.  
  273. XGrid.Rows[I].Clear;
  274. XGrid.ColCount := 0;
  275. End
  276. Else
  277. Begin
  278. XGrid.ColCount := StrToInt(KEdit.Text)*StrToInt(NEdit.Text);
  279.  
  280. End;
  281.  
  282. End;
  283.  
  284. procedure TMainForm.KEditKeyDown(Sender: TObject; var Key: Word;
  285. Shift: TShiftState);
  286. Begin
  287. SelectEdit2(Sender, Key, KEdit);
  288. End;
  289.  
  290. procedure TMainForm.KEditKeyPress(Sender: TObject; var Key: Char);
  291. begin
  292. CheckEdit(Sender, Key, KEdit);
  293. end;
  294.  
  295. procedure TMainForm.ColorizeColumn(StringGrid: TStringGrid; ColumnIndex: Integer; Color: TColor);
  296. var
  297. RowIndex: Integer;
  298. begin
  299. if (ColumnIndex >= 0) and (ColumnIndex < StringGrid.ColCount) then
  300. begin
  301. for RowIndex := 0 to StringGrid.RowCount - 1 do
  302. begin
  303. StringGrid.Canvas.Brush.Color := Color;
  304. StringGrid.Canvas.FillRect(StringGrid.CellRect(ColumnIndex, RowIndex));
  305. StringGrid.Canvas.TextRect(StringGrid.CellRect(ColumnIndex, RowIndex),
  306. StringGrid.CellRect(ColumnIndex, RowIndex).Left + 2,
  307. StringGrid.CellRect(ColumnIndex, RowIndex).Top + 2,
  308. StringGrid.Cells[ColumnIndex, RowIndex]);
  309. end;
  310. end;
  311. end;
  312. Procedure TMainForm.NEditChange(Sender: TObject);
  313. Var
  314. I:Integer;
  315. Begin
  316. If (NEdit.Text = '') Then
  317. Begin
  318. for I := 0 to XGrid.ColCount-1 do
  319.  
  320. XGrid.Rows[I].Clear;
  321. XGrid.ColCount := 0;
  322. End
  323. Else
  324. { XGrid.ColCount := StrToInt(KEdit.Text)*StrToInt(NEdit.Text); }
  325. End;
  326.  
  327. procedure TMainForm.MEditChange(Sender: TObject);
  328. Var
  329. I:Integer;
  330. begin
  331.  
  332. If (MEdit.Text = '' ) Then
  333. Begin
  334. for I := 0 to XGrid.RowCount-1 do
  335. XGrid.Rows[I].Clear;
  336. XGrid.RowCount := 0;
  337. End
  338. Else
  339. XGrid.RowCount := StrToInt(MEdit.Text);
  340. end;
  341.  
  342. Procedure TMainForm.MEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  343. Begin
  344. SelectEdit2(Sender, Key, MEdit);
  345. End;
  346. procedure TMainForm.MEditKeyPress(Sender: TObject; var Key: Char);
  347. begin
  348. CheckEdit(Sender, Key, MEdit);
  349. end;
  350.  
  351. Procedure TMainForm.NEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  352. Begin
  353. SelectEdit2(Sender, Key, NEdit);
  354. End;
  355. Procedure TMainForm.NEditKeyPress(Sender: TObject; Var Key: Char);
  356. Begin
  357. CheckEdit(Sender, Key, NEdit);
  358. End;
  359.  
  360. Procedure TMainForm.OpenMenuClick(Sender: TObject);
  361. Var
  362. X1: Real;
  363. FilePath: String;
  364. F: TextFile;
  365. ErrorCode: TErrorCode;
  366. N1,M1, I,J,K1: Integer;
  367. N,M, X,K: String;
  368. numbers: TArray<string>;
  369. Begin
  370. If MyOpenTextFileDialog.Execute Then
  371. Begin
  372. FilePath := MyOpenTextFileDialog.FileName;
  373. AssignFile(F, FilePath);
  374. ErrorCode := IsAbleToReading(F);
  375. If ErrorCode = EcCorrect Then
  376. Begin
  377. ErrorCode := CheckFileData1(F);
  378. If ErrorCode <> EcCorrect Then
  379. Application.MessageBox(PChar(ERRORS[ErrorCode]), 'Ошибка', MB_OK)
  380. Else
  381. Begin
  382. Reset(F);
  383. Readln(F, M);
  384. MEdit.Text := M;
  385. Readln(F, N);
  386. NEdit.Text := N;
  387. Readln(F, K);
  388. KEdit.Text := K;
  389. N1 := StrToInt(N);
  390. M1 := StrToInt(M);
  391. K1:= StrToInt(k);
  392. For J := 0 To M1 - 1 Do
  393. Begin
  394. Read(F, X);
  395. numbers := X.Split([' ']);
  396. For I := 0 To (N1*K1-1) Do
  397. Begin
  398. XGrid.Cells[I, J] := numbers[I];
  399. End;
  400. Readln(F);
  401. End;
  402. CloseFile(F);
  403. End;
  404. End
  405. Else
  406. Application.MessageBox(PChar(ERRORS[ErrorCode]), 'Ошибка', MB_OK);
  407. End;
  408.  
  409. End;
  410.  
  411.  
  412. Function TMainForm.EnterArr():TArr;
  413. Var
  414. N,M,K,I,J,L,J1:Integer;
  415. RArr:Tarr;
  416. Begin
  417. N:= StrToInt(NEdit.Text);
  418. M:= StrToInt(KEdit.Text);
  419. K:= StrToInt(MEdit.Text);
  420. SetLength(RArr,K,M,N);
  421. J1:=0;
  422. for L := 0 to K-1 do
  423.  
  424. Begin
  425. for I := 0 to M-1 do
  426. Begin
  427. J:=0;
  428. for J:= 0 to N-1 do
  429.  
  430. Begin
  431. RArr[L,I,J]:=StrToInt(XGrid.Cells[J1,I]);
  432. Inc(J1);
  433. End;
  434. End;
  435. End;
  436. EnterArr:= RArr;
  437. End;
  438.  
  439. Function DeletBackspace(EditText: String; Var KeyChar: Char): String;
  440. Begin
  441. If (KeyChar = BACKSPACE) Then
  442. DeletBackspace := EditText
  443. Else
  444. DeletBackspace := EditText + KeyChar;
  445.  
  446. End;
  447.  
  448. Procedure TMainForm.CheckEdit(Sender: TObject; Var Key: Char; CurEdit: TEdit);
  449. Begin
  450. If Not(Key In DIGITS) And Not(Key = BACKSPACE) Then
  451. Key := NONE
  452. Else
  453. Begin
  454. If (Length(CurEdit.Text) < 1) And (Key = '0') Then
  455. Key := NONE;
  456. If (Length(CurEdit.Text) > 1) And Not(CheckUserArea(StrToInt(DeletBackspace(CurEdit.Text, Key)), MAX_N, MIN_N)) Then
  457. Key := NONE;
  458. End;
  459. End;
  460.  
  461. Procedure TMainForm.SelectEdit(Sender: TObject; Var Key: Word);
  462. Begin
  463. With XGrid Do
  464. Begin
  465. If (Key = VK_RIGHT) Then
  466. Begin
  467. If Col < (Colcount - 1) Then
  468. Col := Col + 1
  469. Else
  470. Col := 0;
  471. Key := 0;
  472. End
  473. Else
  474. Begin
  475. If (Key = VK_LEFT) Then
  476. Begin
  477. If Col > 0 Then
  478. Col := Col - 1
  479. Else
  480. Col := Colcount - 1;
  481. Key := 0;
  482. End
  483. Else
  484. Begin
  485. If (Key = VK_Up) Then
  486. Begin
  487. If Row > 0 Then
  488. Row := Row - 1
  489. Else
  490. Row := Rowcount - 1;
  491. Key := 0;
  492. End
  493. Else
  494. Begin
  495. If (Key = VK_Down) Then
  496. Begin
  497. If Row < (Rowcount - 1) Then
  498. Row := Row + 1
  499. Else
  500. Row := 0;
  501. Key := 0;
  502. End;
  503. End;
  504.  
  505. End;
  506.  
  507. End;
  508.  
  509. End;
  510. End;
  511.  
  512. procedure TMainForm.SelectEdit2(Sender: TObject; var Key: Word; CurEdit: TEdit);
  513. begin
  514. with XGrid do
  515. begin
  516. if (Key = VK_RIGHT) or (Key = VK_LEFT) then
  517. XGrid.SetFocus
  518. else if (Key = VK_Up) then
  519. begin
  520. SelectNext(CurEdit, True, True);
  521. end
  522. else if (Key = VK_Down) then
  523. begin
  524. SelectNext(CurEdit, True, False);
  525. end;
  526. end;
  527. end;
  528.  
  529. Function TMainForm.CheckInputFields(Sender: TObject; CurEdit: TEdit; CurStringGrid: TStringGrid): Boolean;
  530. Var
  531. N,M: Byte;
  532. IsCorrect:boolean;
  533. Begin
  534.  
  535. IsCorrect := True;
  536. If (NEdit.Text = '')Or(MEdit.Text = '') Then
  537. Begin
  538. IsCorrect:= False;
  539. CurEdit.SetFocus;
  540. ShowMessage('Введите размер матрицы!');
  541. End
  542. Else
  543. Begin
  544. N := StrToInt(NEdit.Text);
  545. M := StrToInt(MEdit.Text);
  546. If (N < 2) Then
  547. Begin
  548. IsCorrect := False;
  549. CurEdit.Text := '';
  550. CurEdit.SetFocus;
  551. ShowMessage('N не может быть меньше 2!');
  552. End
  553. Else
  554. Begin
  555. If (M < 2) Then
  556. Begin
  557. IsCorrect := False;
  558. CurEdit.Text := '';
  559. CurEdit.SetFocus;
  560. ShowMessage('M не может быть меньше 2!');
  561. End
  562.  
  563. End;
  564.  
  565. End;
  566. If Not(CheckCells(XGrid))And (IsCorrect) Then
  567. Begin
  568. IsCorrect := False;
  569. CurStringGrid.SetFocus;
  570. ShowMessage('Заполните таблицу до конца!');
  571. End;
  572. CheckInputFields:=IsCorrect;
  573.  
  574. End;
  575.  
  576. procedure TMainForm.XGridDrawCell(Sender: TObject; ACol, ARow: Integer;
  577. Rect: TRect; State: TGridDrawState);
  578. begin
  579. Var
  580. K,I,J, N, I1:Integer;
  581. begin
  582. if( KEdit.Text<>'') And (Medit.Text<>'') And (NEdit.Text<>'') then
  583. Begin
  584. K:= StrToInt(KEdit.Text);
  585. N:= StrToInt(NEdit.Text);
  586. I1:=0;
  587. for J := 0 to K-1 do
  588. Begin
  589. for I := 0 to N-1 do
  590.  
  591. Begin
  592. if J Mod 2 = 1 then
  593. ColorizeColumn(XGrid, I1, clRed)
  594. else
  595. if J Mod 2 = 0 then
  596. ColorizeColumn(XGrid, I1, clGreen);
  597. Inc(I1);
  598. End;
  599. End;
  600. end;
  601. end;
  602. end;
  603.  
  604. Procedure TMainForm.XGridKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  605. Begin
  606. SelectEdit(Sender, Key)
  607. End;
  608.  
  609. Procedure TMainForm.XGridSetEditText(Sender: TObject; ACol, ARow: Integer; Const Value: String);
  610. Var
  611. I, J: Integer;
  612. Amount: Extended;
  613. Begin
  614. For I := 0 To XGrid.RowCount Do
  615. Begin
  616. For J := 0 To XGrid.ColCount Do
  617. Begin
  618. If ((Not TryStrToFloat(XGrid.Cells[I, J], Amount)) And (XGrid.Cells[I, J] <> '') And (XGrid.Cells[I, J] <> '-')) Then
  619. Begin
  620. ShowMessage('Некорректные исходные данные!');
  621. XGrid.Cells[I, J] := '';
  622. End
  623. Else
  624. If (XGrid.Cells[I, J] <> '') And (XGrid.Cells[I, J] <> '-') Then
  625. Begin
  626. If Not(CheckXArea(StrToFloat(XGrid.Cells[I, J]), MAX_X, MIN_X)) Then
  627. Begin
  628.  
  629. ShowMessage('Некорректные исходные данные!');
  630. XGrid.Cells[I, J] := '';
  631. End;
  632. End;
  633. End;
  634. End;
  635.  
  636. End;
  637.  
  638. Procedure TMainForm.CalcResult(Sender: TObject);
  639. Var
  640. Count, I, J: Integer;
  641. IsCorrect: Boolean;
  642. Begin
  643. Count := 0;
  644. IsCorrect := True;
  645. For J := 0 To StrToInt(MEdit.Text) - 1 Do
  646. Begin
  647. For I := 0 To StrToInt(NEdit.Text) - 2 Do
  648. Begin
  649. If (StrToFloat(XGrid.Cells[I, J]) >= (StrToFloat(XGrid.Cells[I+1, J]))) Then
  650. Begin
  651. IsCorrect := False;
  652. End;
  653.  
  654. End;
  655. If IsCorrect Then
  656. Inc(Count);
  657. IsCorrect := True;
  658. End;
  659. ResultEdit.Text:='Количество отсортированных по возрастанию строк матрицы: '+IntToStr(Count);
  660. End;
  661.  
  662. Procedure TMainForm.GridCheck(Sender: TObject);
  663. Var
  664. I,J: Integer;
  665. Amount: Extended;
  666. IsExistCell:Boolean;
  667. Begin
  668. IsExistCell := True;
  669. For I := 0 To (XGrid.RowCount)-1 Do
  670. Begin
  671. For J := 0 To XGrid.ColCount-1 Do
  672. Begin
  673. If (XGrid.Cells[I, J] = '-') Then
  674. Begin
  675. IsExistCell := False;
  676. XGrid.Cells[I, J] := ''
  677. End;
  678. End;
  679. End;
  680. if Not(IsExistCell) then
  681. ShowMessage('Некорректные исходные данные!');
  682. End;
  683.  
  684. Procedure TMainForm.ResultButtonClick(Sender: TObject);
  685. Begin
  686. GridCheck(Sender);
  687. If CheckInputFields(Sender, NEdit, XGrid) Then
  688. CalcResult(Sender);
  689. End;
  690.  
  691. Var
  692. IsSave: Boolean = False;
  693.  
  694. Procedure TMainForm.SaveMenuClick(Sender: TObject);
  695. Var
  696. FilePath: String;
  697. F: TextFile;
  698. Begin
  699. If (ResultEdit.Text <> '') Then
  700. Begin
  701. If MySaveTextFileDialog.Execute Then
  702. Begin
  703. FilePath := MySaveTextFileDialog.FileName;
  704. AssignFile(F, FilePath);
  705. If FileIsReadOnly(FilePath) Then
  706. Application.MessageBox(PChar(ERRORS[EcNot_Writeable]), 'Ошибка', MB_OK + MB_ICONERROR)
  707. Else
  708. Begin
  709. Rewrite(F);
  710. Write(F, ResultEdit.Text);
  711. CloseFile(F);
  712. IsSave := True;
  713. End;
  714. End;
  715. End;
  716.  
  717. End;
  718.  
  719. Procedure TMainForm.FileMenuClick(Sender: TObject);
  720. Begin
  721. If ResultEdit.Text<>'' Then
  722. SaveMenu.Enabled := True
  723. Else
  724. SaveMenu.Enabled := False;
  725. End;
  726.  
  727. Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
  728. Var
  729. IsExit: Word;
  730. Begin
  731. If Not IsSave And (ResultEdit.Text <> '') Then
  732. Begin
  733. IsExit := Application.MessageBox('Вы не сохранили файл, хотите ли сохранить?', 'Выход', MB_YESNOCANCEL + MB_ICONQUESTION);
  734. Case IsExit Of
  735. MrYes:
  736. Begin
  737. CanClose := False;
  738. FileMenu.Click;
  739. SaveMenu.Click;
  740. End;
  741.  
  742. MrNo:
  743. CanClose := True;
  744. MrCancel:
  745. CanClose := False;
  746. End;
  747.  
  748. End
  749. Else
  750. Begin
  751. IsExit := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION);
  752. Case IsExit Of
  753. MrYes:
  754. CanClose := True;
  755. MrNo:
  756. CanClose := False;
  757. End;
  758. End;
  759. End;
  760.  
  761. Procedure TMainForm.FormCreate(Sender: TObject);
  762. Begin
  763. TaskLabel.Caption := 'Данная программа подсчитывает количество строк заданной матрицы, которые упорядочены по возрастанию.';;
  764. End;
  765.  
  766. function TMainForm.CheckCells(CurStringGrid: TStringGrid): Boolean;
  767. var
  768. I, J: Integer;
  769. begin
  770. Result := True;
  771.  
  772. for I := 0 to CurStringGrid.RowCount - 1 do
  773. begin
  774. for J := 0 to CurStringGrid.ColCount - 1 do
  775. begin
  776. if CurStringGrid.Cells[J, I] = '' then
  777. begin
  778. Result := False;
  779. Exit; // Если найдена пустая ячейка, выходим из функции
  780. end;
  781. end;
  782. end;
  783. end;
  784. Procedure TMainForm.ExitMenuClick(Sender: TObject);
  785. Var
  786. IsExit: Word;
  787. Begin
  788. If Not IsSave And (ResultEdit.Text <> '') Then
  789. Begin
  790. IsExit := Application.MessageBox('Вы не сохранили файл, хотите ли сохранить?', 'Выход', MB_YESNOCANCEL + MB_ICONQUESTION);
  791. Case IsExit Of
  792. MrYes:
  793. SaveMenu.Click;
  794. MrNo:
  795. Close;
  796. End;
  797.  
  798. End
  799. Else
  800. Begin
  801. IsExit := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION);
  802. Case IsExit Of
  803. MrYes:
  804. Close;
  805. End;
  806. End;
  807. End;
  808.  
  809. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement