Advertisement
believe_me

Untitled

May 18th, 2022
1,944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function TEditForm.IsCorrectTextData(CurrentEdit: TEdit): boolean;
  2. var
  3.     IsCorrectInput: boolean;
  4.     TextLength, i: integer;
  5. begin
  6.     isCorrectInput := false;
  7.     TextLength := length(CurrentEdit.text);
  8.     i := 2;
  9.     if TextLength <= CurrentEdit.MaxLength then
  10.     begin
  11.         if TextLength = 0 then
  12.             IsCorrectInput := true
  13.         else
  14.         begin
  15.             if (TextLength = 1) and (CurrentEdit.text[1] in BIG_LETTERS) then
  16.                 IsCorrectInput := True
  17.             else
  18.             begin
  19.                 IsCorrectInput := CurrentEdit.text[1] in BIG_LETTERS;
  20.                 while IsCorrectInput and (i <= TextLength) do
  21.                 begin
  22.                     if not(CurrentEdit.text[i] in SMALL_LETTERS) then
  23.                         IsCorrectInput := false;
  24.                     inc(i);
  25.                 end;
  26.             end;
  27.         end;
  28.     end;
  29.     Result := IsCorrectInput;
  30. end;
  31.  
  32. procedure TEditForm.fillStringGrid(SubscribersStringGrid: TStringGrid;
  33.                             TelephoneEdit, SurnameEdit, NameEdit,
  34.                                 PatronymicEdit, CityEdit: TEdit);
  35. var
  36.     i, j, ListLength: Integer;
  37.     PCurrentSubscriber: TSubscriberPointer;
  38.     RequiredSubscriber: TRequiredSubscriber;
  39. begin
  40.     i := 1;
  41.     j := 0;
  42.     SubscriberList.deleteList();
  43.     getRequiredSubscriber(RequiredSubscriber, TelephoneEdit.text, SurnameEdit.text, NameEdit.text,
  44.                                 PatronymicEdit.text, CityEdit.text);
  45.     readSubscribers(RequiredSubscriber);
  46.     sortList();
  47.     ListLength := SubscriberList.length();
  48.     setlength(NumberArray, ListLength);
  49.     PCurrentSubscriber := SubscriberList.getHeader()^.next;
  50.     while (PCurrentSubscriber <> nil) do
  51.     begin
  52.         SubscribersStringGrid.RowCount := SubscribersStringGrid.RowCount + 1;
  53.         SubscribersStringGrid.Cells[0, i] := intToStr(i);
  54.         SubscribersStringGrid.Cells[1, i] := PCurrentSubscriber^.telephoneNumber;
  55.         SubscribersStringGrid.Cells[2, i] := PCurrentSubscriber^.surname;
  56.         SubscribersStringGrid.Cells[3, i] := PCurrentSubscriber^.name;
  57.         SubscribersStringGrid.Cells[4, i] := PCurrentSubscriber^.patronymic;
  58.         SubscribersStringGrid.Cells[5, i] := PCurrentSubscriber^.city;
  59.         SubscribersStringGrid.Cells[6, i] := intToStr(PCurrentSubscriber^.numberOfDays);
  60.         NumberArray[j] := PCurrentSubscriber^.number;
  61.         Inc(i);
  62.         inc(j);
  63.         PCurrentSubscriber := PCurrentSubscriber^.next;
  64.     end;
  65. end;
  66.  
  67. procedure TEditForm.ClearButtonClick(Sender: TObject);
  68. begin
  69.     TelephoneEdit.text := '';
  70.     NameEdit.text := '';
  71.     SurnameEdit.text := '';
  72.     PatronymicEdit.text := '';
  73.     CityEdit.text := '';
  74.     TelephoneRButton.Checked := false;
  75.     SurnameRButton.Checked := false;
  76.     NameRButton.Checked := false;
  77.     PatronymicRButton.Checked := false;
  78.     CityRButton.Checked := false;
  79.     DateRButton.Checked := false;
  80.     CurrentRadioButton := 0;
  81.     SubscribersStringGrid.RowCount := 1;
  82.     EditButton.Enabled := false;
  83.     DeleteButton.Enabled := false;
  84. end;
  85.  
  86. procedure TEditForm.DataEditKeyPress(Sender: TObject; var Key: Char);
  87. begin
  88.     if (Key <> #08) then
  89.     begin
  90.         if length((Sender as TEdit).text) = 0 then
  91.         begin
  92.             if not (Key in BIG_LETTERS) then
  93.                 Key := #0
  94.         end
  95.         else
  96.             if not(Key in SMALL_LETTERS) then
  97.                 Key := #0;
  98.     end;
  99. end;
  100.  
  101. procedure TEditForm.ShowButtonClick(Sender: TObject);
  102. begin
  103.     if areEditsCorrect() then
  104.     begin
  105.         clearStringGrid();
  106.         if not isFileEmpty() then
  107.         begin
  108.             fillStringGrid(SubscribersStringGrid, TelephoneEdit, SurnameEdit, NameEdit,
  109.                             PatronymicEdit, CityEdit);
  110.             setEditButtonsCondition();
  111.         end
  112.         else
  113.             MessageDlg('Subscriber file is empty.', mtError, [mbOk], 0, mbOk);
  114.     end
  115.     else
  116.     begin
  117.         MessageDlg('Wrong data.', mtError, [mbCancel], 0);
  118.         clearButtonClick(Sender);
  119.     end;
  120. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement