sendunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:1k
- unit sendunit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Buttons;
- type
- TForm1 = class(TForm)
- Edit1: TEdit;
- Label1: TLabel;
- BitBtn1: TBitBtn;
- procedure BitBtn1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- private
- { Private declarations }
- public
- procedure SendData;
- { Public declarations }
- end;
- var
- Form1: TForm1;
- MapFilehWnd: THandle;
- MapFilePointer: Pointer;
- implementation
- {$R *.dfm}
- procedure TForm1.SendData; //发送消息和数据过程
- begin
- MapFilehWnd := CreateFileMapping ($FFFFFFFF,nil,page_ReadWrite, 0,10000,'MapFileDemo');
- if MapFilehWnd <> 0 then
- begin
- MapFilePointer := MapViewOfFile (MapFilehWnd ,FILE_MAP_ALL_ACCESS,0, 0, 0);
- StrCopy(PChar(MapFilePointer),PChar (Edit1.Text));
- end;
- end;
- procedure TForm1.BitBtn1Click(Sender: TObject);
- begin
- if Edit1.Text<>'' then
- SendData;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- MapFilehWnd:=0;
- MapFilePointer:=Nil;
- end;
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if MapFilePointer<>Nil then
- begin
- UnmapViewOfFile(MapFilePointer);
- CloseHandle(MapFilehWnd);
- end;
- end;
- end.