Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit MainUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Classes,
- Vcl.Forms,
- Vcl.ExtDlgs,
- Vcl.Menus,
- Vcl.StdCtrls,
- Vcl.Grids,
- Vcl.Dialogs,
- Vcl.Controls,
- ManualUnit,
- DevInfUnit,
- AddUnit,
- BackUnit,
- LinkedListUnit;
- Type
- TMainForm = Class(TForm)
- MainMenu: TMainMenu;
- FileButtonMenu: TMenuItem;
- ExitButtonMenu: TMenuItem;
- ManualButtonMenu: TMenuItem;
- DeveloperButtonMenu: TMenuItem;
- PopupMenu: TPopupMenu;
- SaveDialog1: TSaveTextFileDialog;
- CheckButton: TButton;
- InfLabel: TLabel;
- FirstListLabel: TLabel;
- SecondListLabel: TLabel;
- SecondListGrid: TStringGrid;
- AddFirstButton: TButton;
- AddSecondButton: TButton;
- SaveButtonMenu: TMenuItem;
- FirstListGrid: TStringGrid;
- MergedListGrid: TStringGrid;
- OpenFileButton: TMenuItem;
- Opendialog1: TOpenTextFileDialog;
- Procedure ManualButtonMenuClick(Sender: TObject);
- Procedure DeveloperButtonMenuClick(Sender: TObject);
- Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Procedure ExitButtonMenuClick(Sender: TObject);
- Procedure FormCreate(Sender: TObject);
- Procedure SaveButtonMenuClick(Sender: TObject);
- Procedure AddFirstButtonClick(Sender: TObject);
- Procedure AddSecondButtonClick(Sender: TObject);
- Procedure CheckButtonClick(Sender: TObject);
- Function FormHelp(Command: Word; Data: NativeInt; Var CallHelp: Boolean): Boolean;
- Procedure OpenFileButtonClick(Sender: TObject);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Procedure Add(HeadPt: ListPointer; Elem: String); Stdcall; External 'ListLib.dll';
- Function Len(HeadPt: ListPointer): Integer; Stdcall; External 'ListLib.dll';
- Procedure Merge(Dest, First, Second: ListPointer); Stdcall; External 'ListLib.dll';
- Type
- TGridCracker = Class(TStringGrid);
- Var
- MainForm: TMainForm;
- IsSaved: Boolean = True;
- FirstHead, SecondHead: ListPointer;
- Implementation
- {$R *.dfm}
- Procedure FillGrid(HeadPt: ListPointer; Grid: TStringGrid);
- Var
- I, Size: Integer;
- Begin
- Grid.Visible := True;
- Size := Len(HeadPt);
- If Size > 5 Then
- Begin
- Grid.Width := (Grid.DefaultColWidth + 3) * 5;
- Grid.Height := (Grid.DefaultRowHeight + 3) * 2 + 25;
- End
- Else
- Begin
- Grid.Width := (Grid.DefaultColWidth + 4) * Size;
- Grid.Height := (Grid.DefaultRowHeight + 3) * 2;
- End;
- Grid.ColCount := Size;
- Grid.RowCount := 2;
- For I := 0 To Size - 1 Do
- Begin
- HeadPt := HeadPt^.Next;
- Grid.Cells[I, 0] := IntToStr(I + 1);
- Grid.Cells[I, 1] := IntToStr(HeadPt^.Data);
- End;
- End;
- Procedure ClearGrid(Grid: TStringGrid);
- Var
- J, I: Integer;
- Begin
- Grid.Visible := False;
- For I := 0 To Grid.ColCount - 1 Do
- For J := 0 To Grid.RowCount - 1 Do
- Grid.Cells[I, J] := '';
- End;
- Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Begin
- If SaveButtonMenu.Enabled And Not IsSaved Then
- Case Application.MessageBox('Сохранить данные перед выходом?', 'Выход', MB_YESNOCANCEL + MB_ICONQUESTION + MB_DEFBUTTON3) Of
- IDYES:
- Begin
- SaveButtonMenu.Click;
- CanClose := True;
- End;
- IDNO:
- CanClose := True;
- IDCANCEL:
- CanClose := False;
- End
- Else
- Case Application.MessageBox('Вы точно хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) Of
- IDYES:
- CanClose := True;
- IDNO:
- CanClose := False;
- End;
- End;
- Procedure TMainForm.FormCreate(Sender: TObject);
- Begin
- New(FirstHead);
- FirstHead^.Next := Nil;
- New(SecondHead);
- SecondHead^.Next := Nil;
- End;
- Function TMainForm.FormHelp(Command: Word; Data: NativeInt; Var CallHelp: Boolean): Boolean;
- Begin
- ManualButtonMenu.Click();
- CallHelp := False;
- End;
- Function ReadOneFromFile(Var Numb: Integer; Var MyFile: TextFile; IsElemRead: Boolean = True): ERRORS_CODE;
- Var
- Err: ERRORS_CODE;
- NumbInt: Integer;
- NumbStr: String;
- Begin
- Err := SUCCESS;
- NumbInt := 0;
- Try
- Read(MyFile, NumbInt);
- Except
- Err := INCORRECT_DATA_FILE;
- End;
- If Err = SUCCESS Then
- If IsElemRead Then
- If (NumbInt > MAX_NUMB) Or (NumbInt < MIN_NUMB) Then
- Err := OUT_OF_BORDER
- Else
- Numb := NumbInt
- Else
- If (NumbInt > MAX_SIZE) Or (NumbInt < MIN_SIZE) Then
- Err := OUT_OF_BORDER_SIZE
- Else
- Numb := NumbInt;
- ReadOneFromFile := Err;
- End;
- Procedure TMainForm.SaveButtonMenuClick(Sender: TObject);
- Var
- OutFile: TextFile;
- I, J: Integer;
- Begin
- If SaveDialog1.Execute() Then
- Begin
- AssignFile(OutFile, SaveDialog1.FileName);
- Rewrite(OutFile);
- Writeln(OutFile, 'Итоговый список');
- For I := 0 To MergedListGrid.ColCount - 1 Do
- Write(OutFile, MergedListGrid.Cells[I, 1] + ' ');
- CloseFile(OutFile);
- IsSaved := True;
- End;
- End;
- Procedure TMainForm.ManualButtonMenuClick(Sender: TObject);
- Var
- ManualForm: TManualForm;
- Begin
- ManualForm := TManualForm.Create(Self);
- ManualForm.ShowModal;
- ManualForm.Free;
- End;
- Procedure TMainForm.OpenFileButtonClick(Sender: TObject);
- CONST
- FIRST = 1;
- SECOND = 2;
- Var
- FileName: String;
- FileStatus: TFileStatus;
- Size: Integer;
- Begin
- If OpenDialog1.Execute() Then
- Begin
- FileName := OpenDialog1.FileName;
- FileStatus := CheckFile(FileName);
- If FileStatus = FsGood Then
- Begin
- Size := ReadSize(Filename, FIRST, FileStatus);
- If FileStatus = FsGood Then
- FirstHead := ReadList(FileName, Size, FIRST, FileStatus)
- Else
- MessageBox(Self.Handle, ListOfMessages[FileStatus], 'Ошибка', MB_ICONERROR);
- End
- Else
- MessageBox(Self.Handle, ListOfMessages[FileStatus], 'Ошибка', MB_ICONERROR);
- If FileStatus = FsGood Then
- Begin
- Size := ReadSize(Filename, SECOND, FileStatus);
- If FileStatus = FsGood Then
- SecondHead := ReadList(FileName, Size, SECOND, FileStatus)
- Else
- MessageBox(Self.Handle, ListOfMessages[FileStatus], 'Ошибка', MB_ICONERROR);
- End
- Else
- MessageBox(Self.Handle, ListOfMessages[FileStatus], 'Ошибка', MB_ICONERROR);
- If FileStatus = FsGood Then
- Begin
- FillGrid(FirstHead, FirstListGrid);
- ClearGrid(MergedListGrid);
- FillGrid(SecondHead, SecondListGrid);
- CheckButton.Enabled := True;
- End;
- End;
- End;
- Procedure TMainForm.AddFirstButtonClick(Sender: TObject);
- Var
- AddForm: TAddForm;
- Res: TModalResult;
- NewElem: Integer;
- Begin
- AddForm := TAddForm.Create(Self);
- AddForm.FormCreate(FirstHead, Self);
- Res := AddForm.ShowModal();
- If Res = MrOk Then
- Begin
- FillGrid(FirstHead, FirstListGrid);
- ClearGrid(MergedListGrid);
- End;
- AddForm.Free();
- If FirstListGrid.Visible And SecondListGrid.Visible Then
- CheckButton.Enabled := True;
- End;
- Procedure TMainForm.AddSecondButtonClick(Sender: TObject);
- Var
- AddForm: TAddForm;
- Res: TModalResult;
- NewElem: Integer;
- Begin
- AddForm := TAddForm.Create(Self);
- AddForm.FormCreate(SecondHead, Self);
- Res := AddForm.ShowModal();
- If Res = MrOk Then
- FillGrid(SecondHead, SecondListGrid);
- AddForm.Free();
- If FirstListGrid.Visible And SecondListGrid.Visible Then
- CheckButton.Enabled := True;
- End;
- Procedure TMainForm.CheckButtonClick(Sender: TObject);
- Var
- MergedHead: ListPointer;
- Begin
- New(MergedHead);
- Merge(MergedHead, FirstHead, SecondHead);
- FillGrid(MergedHead, MergedListGrid);
- SaveButtonMenu.Enabled := True;
- IsSaved := False;
- End;
- Procedure TMainForm.DeveloperButtonMenuClick(Sender: TObject);
- Var
- DeveloperForm: TDeveloperForm;
- Begin
- DeveloperForm := TDeveloperForm.Create(Self);
- DeveloperForm.ShowModal;
- DeveloperForm.Free;
- End;
- Procedure TMainForm.ExitButtonMenuClick(Sender: TObject);
- Begin
- Close();
- End;
- Function IsAllCellFill(Grid: TStringGrid; Key: Char; CurCell: TInplaceEdit): Boolean;
- Var
- IsFilled: Boolean;
- I, J: Integer;
- Begin
- IsFilled := True;
- For I := 1 To Grid.ColCount - 1 Do
- For J := 1 To Grid.RowCount - 1 Do
- Begin
- If (Grid.Col = I) And (Grid.Row = J) And Not(Key = VOID) Then
- Begin
- If (Grid.Cells[I, J] = '') And Not CharInSet(Key, DIGITS) Then
- IsFilled := False;
- With CurCell Do
- If (Key = BACKSPACE) And (InsertKey(SelStart, Key, SelLength, Text) = '') Then
- IsFilled := False;
- End
- Else
- If (Grid.Cells[I, J] = '') Or (Grid.Cells[I, J] = '-') Then
- IsFilled := False;
- End;
- IsAllCellFill := IsFilled;
- End;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement