MainFrm.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:3k
- unit MainFrm;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, FileMap;
- type
- TfrmMain = class(TForm)
- btnWriteMap: TButton;
- btnReadMap: TButton;
- btnClear: TButton;
- chkExistsAlready: TCheckBox;
- chkIsMapOpen: TCheckBox;
- btnOpenMap: TButton;
- btnCloseMap: TButton;
- mmoCont: TMemo;
- chkAutoSynchronize: TCheckBox;
- Label5: TLabel;
- lblHelp: TLabel;
- procedure btnWriteMapClick(Sender: TObject);
- procedure btnReadMapClick(Sender: TObject);
- procedure btnClearClick(Sender: TObject);
- procedure btnOpenMapClick(Sender: TObject);
- procedure btnCloseMapClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure chkAutoSynchronizeClick(Sender: TObject);
- procedure mmoContKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- private
- //定义TFileMap的对象
- FileMap: TFileMap;
- //定义FileMapChange用于赋给FileMap的OnChange事件
- procedure FileMapChange(Sender: TObject);
- procedure Check;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmMain: TfrmMain;
- implementation
- {$R *.DFM}
- //检查FileMap的ExistsAlready和IsMapOpen属性
- procedure TfrmMain.Check;
- begin
- chkExistsAlready.Checked := FileMap.ExistsAlready;
- chkIsMapOpen.Checked := FileMap.IsMapOpen;
- end;
- //在窗体创建时,初始化FileMap对象
- procedure TfrmMain.FormCreate(Sender: TObject);
- begin
- //创建对象FileMap
- FileMap := TFileMap.Create(self);
- FileMap.OnChange := FileMapchange;
- chkAutoSynchronize.Checked := FileMap.AutoSynchronize;
- //如果内存对象还未创建,初始化FileMap里的内容
- if not FileMap.ExistsAlready then
- begin
- MmoCont.Lines.LoadFromFile('Project1.dpr');
- FileMap.MapStrings.Assign(MmoCont.Lines);
- end;
- lblHelp.Caption := '使用说明:运行两个或多个此应用程序,按下“打开内存映射”按钮,'
- + #13 + '选中“是否同步”复选框,在备注框里改动,在另外的应用程序中将会'
- + #13 + '该动后的信息,同时也可以读写数据按钮来获取共享信息'
- end;
- //写入内存文件映射的数据
- procedure TfrmMain.btnWriteMapClick(Sender: TObject);
- begin
- FileMap.WriteMap;
- end;
- //读取内存文件映射的数据
- procedure TfrmMain.btnReadMapClick(Sender: TObject);
- begin
- FileMap.ReadMap;
- end;
- //清除内存文件数据
- procedure TfrmMain.btnClearClick(Sender: TObject);
- begin
- Mmocont.Clear;
- FileMap.MapStrings.Clear;
- check;
- end;
- //打开内存文件映射
- procedure TfrmMain.btnOpenMapClick(Sender: TObject);
- begin
- FileMap.MapName := 'Delphi 6 ';
- FileMap.OpenMap;
- check;
- end;
- //关闭内存映射
- procedure TfrmMain.btnCloseMapClick(Sender: TObject);
- begin
- FileMap.CloseMap;
- Check;
- end;
- //当内存映射文件的数据改变时,显示最新数据
- procedure TfrmMain.FileMapChange(Sender: TObject);
- begin
- Mmocont.Lines.Assign(FileMap.MapStrings);
- Check;
- end;
- //设置是否同步显示
- procedure TfrmMain.chkAutoSynchronizeClick(Sender: TObject);
- begin
- FileMap.AutoSynchronize := chkAutoSynchronize.Checked;
- end;
- //在备注框里写时,同时更新进内存映射文件
- procedure TfrmMain.mmoContKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- FileMap.MapStrings.Assign(MmoCont.Lines);
- end;
- end.