unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Label1: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure run(var Msg: integer); message WM_USER;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
n=20;
k=3;

var
  Form1: TForm1;
  hMappedFile: THandle;
  p: ^integer;
  mas: array [1..n] of integer;
  er: boolean;

implementation

{$R *.dfm}

function Solve: integer;
var
i, rez: integer;
begin
rez:=0;
for i:=1 to n do
  if (mas[i] mod 3)=0 then
    inc(rez);
Solve:=rez;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnMapViewOfFile(p);
CloseHandle(hMappedFile);
end;

procedure TForm1.run;
var
i: integer;
begin
er:=false;
hMappedFile:=CreateFileMapping($FFFFFFFF, nil, PAGE_READONLY, 0, SizeOf(integer)*n, 'Saneea');

if hMappedFile<>0 then
  begin
  p:=MapViewOfFile(hMappedFile, FILE_MAP_READ, 0, 0, 0);
  if p=nil then
    er:=true;
  end
else
  er:=true;

if er then
  ShowMessage('Произошла ошибка')
else
  begin
  for i:=1 to n do
    begin
    mas[i]:=p^;
    inc(p);
    ListBox1.Items.Add(IntToStr(mas[i]));
    end;
  Label1.Caption:='Кратных '+IntToStr(k)+' чисел - '+IntToStr(Solve)+' штук';
  ShowMessage('Данные приняты!');
  end;
end;

end.
