sendunit.pas
来自「Delphi 7经典问题解析」· PAS 代码 · 共 63 行
PAS
63 行
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.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?