Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Library anticlown;
- uses
- ShareMem,
- System.SysUtils,
- System.Classes,
- Vcl.Forms,
- Vcl.Dialogs;
- {$R *.res}
- Type
- TArr = Array Of Integer;
- //Для двух чисел
- Function IsFileOfNumbersCorrect(Path: String): Boolean; stdcall;
- Const
- MIN_VALUE = 1;
- MAX_VALUE = 10;
- Var
- InputFile: TextFile;
- Participants, NumberOut: Single;
- IsCorrect: Boolean;
- Begin
- AssignFile(InputFile, Path);
- IsCorrect := True;
- Try
- Try
- Reset(InputFile);
- Readln(InputFile, Participants);
- Readln(InputFile, NumberOut);
- If ((Participants < MIN_VALUE) Or (Participants > MAX_VALUE) Or (NumberOut < MIN_VALUE) Or (NumberOut > Participants)) Then
- IsCorrect := False;
- Finally
- CloseFile(InputFile);
- End;
- Except
- IsCorrect := False;
- End;
- IsFileOfNumbersCorrect := IsCorrect;
- End;
- Procedure GetNumbersFromFile(Path: String; Var Participants, NumberOut: Integer; Var IsCorrect: Boolean); stdcall;
- Var
- InputFile: TextFile;
- Null: String;
- Begin
- IsCorrect := True;
- Try
- AssignFile(InputFile, Path);
- Try
- Reset(InputFile);
- Readln(InputFile, Null);
- If (Null <> '') Then
- IsCorrect := True
- Else
- Begin
- IsCorrect := False;
- ShowMessage(Pchar('Файл пуст!'));
- End;
- Finally
- Close(InputFile);
- End;
- Except
- ShowMessage(Pchar('Ошибка доступа!'));
- End;
- If (IsCorrect) Then
- Begin
- Try
- Try
- Reset(InputFile);
- Readln(InputFile, Participants);
- Readln(InputFile, NumberOut);
- Finally
- Close(InputFile);
- End;
- Except
- IsCorrect := False;
- End;
- End;
- End;
- //Для одномерного массива
- Function IsFileOfArrCorrect(Path: String): Boolean; stdcall;
- Const
- MIN_SIZE = 2;
- MAX_SIZE = 10;
- MIN_VALUE = -99;
- MAX_VALUE = 99;
- Var
- InputFile: TextFile;
- Number: Single;
- IsCorrect: Boolean;
- Sequence: TArr;
- I: Integer;
- Begin
- AssignFile(InputFile, Path);
- IsCorrect := True;
- Try
- Try
- Reset(InputFile);
- Readln(InputFile, Number);
- If (Number < MIN_SIZE) Or (Number > MAX_SIZE) Then
- IsCorrect := False
- Else
- Begin
- SetLength(Sequence, Round(Number));
- I := 0;
- While (IsCorrect) And (I < Number) Do
- Begin
- Read(InputFile, Sequence[I]);
- If (Sequence[I] < MIN_VALUE) Or (Sequence[I] > MAX_VALUE) Then
- IsCorrect := False;
- Inc(I);
- End;
- End;
- Finally
- CloseFile(InputFile);
- End;
- Except
- IsCorrect := False;
- End;
- IsFileOfArrCorrect := IsCorrect;
- End;
- Procedure GetSizeFromFile(Path: String; Var Size: Single; Var IsCorrect: Boolean); stdcall;
- Var
- InputFile: TextFile;
- Null: String;
- Begin
- IsCorrect := True;
- Try
- AssignFile(InputFile, Path);
- Try
- Reset(InputFile);
- Readln(InputFile, Null);
- If (Null <> '') Then
- IsCorrect := True
- Else
- Begin
- IsCorrect := False;
- ShowMessage(Pchar('Файл пуст!'))
- End;
- Finally
- Close(InputFile);
- End;
- Except
- ShowMessage(Pchar('Ошибка доступа!'))
- End;
- If (IsCorrect) Then
- Begin
- Try
- Try
- Reset(InputFile);
- Readln(InputFile, Size);
- Finally
- Close(InputFile);
- End;
- Except
- IsCorrect := False;
- End;
- End;
- End;
- Function GetSequenceFromFile(Path: String; Size: Integer; Sequence: TArr; Var IsCorrect: Boolean): TArr; stdcall;
- Var
- InputFile: TextFile;
- I, FinalI: Integer;
- Null: String;
- Begin
- IsCorrect := True;
- FinalI := Size;
- Try
- AssignFile(InputFile, Path);
- Try
- Reset(InputFile);
- Readln(InputFile);
- Readln(InputFile, Null);
- If (Null <> '') Then
- IsCorrect := True
- Else
- Begin
- IsCorrect := False;
- ShowMessage(Pchar('Файл пуст!'))
- End;
- Finally
- Close(InputFile);
- End;
- Except
- ShowMessage(Pchar('Ошибка доступа!'))
- End;
- If (IsCorrect) Then
- Begin
- Try
- Try
- Reset(InputFile);
- Readln(InputFile);
- For I := 0 To FinalI Do
- Read(InputFile, Sequence[I]);
- Finally
- Close(InputFile);
- End;
- Except
- IsCorrect := False;
- End;
- End;
- GetSequenceFromFile := Sequence;
- End;
- Exports
- IsFileOfNumbersCorrect,
- GetNumbersFromFile,
- IsFileOfArrCorrect,
- GetSizeFromFile,
- GetSequenceFromFile;
- Begin
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement