Еще раз об отображаемом в память файле

Советы » Файлы » Еще раз об отображаемом в память файле

unit

MapWForm; interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, SyncObjs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, Grids, ComCtrls; type

TForm1 = class

(TForm) Timer1: TTimer; TrackBar1: TTrackBar; Label1: TLabel; procedure

FormCreate(Sender: TObject); procedure

FormDestroy(Sender: TObject); procedure

Timer1Timer(Sender: TObject); procedure

TrackBar1Change(Sender: TObject); private

hMapFile: THandle; MapFilePointer: Pointer; end

; var

Form1: TForm1; implementation

{$R *.DFM} procedure

TForm1.FormCreate(Sender: TObject); begin

hMapFile := CreateFileMapping( $FFFFFFFF, // file handle ... or memory nil

, // security Page_ReadWrite, // access rights 0, // high memory size 10000, // low memory size 'DdhMappedFileGraph'); // mapped file name if

hMapFile <> 0 then

MapFilePointer := MapViewOfFile( hMapFile, // handle returned above File_Map_All_Access, // access rights 0, 0, 0) // access the entire mapped file else

ShowMessage('hMapFile = 0'); if

MapFilePointer = nil

then

ShowMessage('MapFilePointer = nil'); // not a listener of messages... TrackBar1.Position := 1 + Random(10); Label1.Caption := IntToStr(TrackBar1.Position) end

; procedure

TForm1.FormDestroy(Sender: TObject); begin

UnMapViewOfFile(MapFilePointer); CloseHandle(hMapFile); end

; procedure

TForm1.Timer1Timer(Sender: TObject); var

X, Y: Integer; Address: Pointer; begin

X := TrackBar1.Position - 1; Y := Random(10); Address := pChar(MapFilePointer) + (X + Y * 10) * 4; PInteger(Address)^ := PInteger(Address)^ + Random(10); Address := pChar(MapFilePointer) + 400; while

PInteger(Address)^ <> 0 do

begin

PostMessage(PInteger(Address)^, wm_user, 0, 0); Address := pChar(Address) + 4; end

; end

; procedure

TForm1.TrackBar1Change(Sender: TObject); begin

Label1.Caption := IntToStr(TrackBar1.Position) end

; initialization

Randomize; end

.

Другое по теме:

Категории

Статьи

Советы

Copyright © 2022 - All Rights Reserved - www.delphirus.com