1 |
(* ***** BEGIN LICENSE BLOCK *****
|
2 |
* Version: MPL 1.1
|
3 |
*
|
4 |
* The contents of this file are subject to the Mozilla Public License Version
|
5 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
6 |
* the License. You may obtain a copy of the License at
|
7 |
* http://www.mozilla.org/MPL/
|
8 |
*
|
9 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
10 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
11 |
* for the specific language governing rights and limitations under the
|
12 |
* License.
|
13 |
*
|
14 |
* The Original Code is TurboPower SysTools
|
15 |
*
|
16 |
* The Initial Developer of the Original Code is
|
17 |
* TurboPower Software
|
18 |
*
|
19 |
* Portions created by the Initial Developer are Copyright (C) 1996-2002
|
20 |
* the Initial Developer. All Rights Reserved.
|
21 |
*
|
22 |
* Contributor(s):
|
23 |
*
|
24 |
* ***** END LICENSE BLOCK ***** *)
|
25 |
|
26 |
unit exmmfsu;
|
27 |
|
28 |
interface
|
29 |
|
30 |
uses
|
31 |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
32 |
StdCtrls,
|
33 |
|
34 |
StStrms;
|
35 |
|
36 |
type
|
37 |
TfrmMain = class(TForm)
|
38 |
Edit1: TEdit;
|
39 |
btnUpdate: TButton;
|
40 |
btnOpenMMF: TButton;
|
41 |
btnCloseMMF: TButton;
|
42 |
Label1: TLabel;
|
43 |
procedure btnOpenMMFClick(Sender: TObject);
|
44 |
procedure btnCloseMMFClick(Sender: TObject);
|
45 |
procedure btnUpdateClick(Sender: TObject);
|
46 |
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
47 |
private
|
48 |
{ Private declarations }
|
49 |
public
|
50 |
{ Public declarations }
|
51 |
|
52 |
AMMFile : TStMemoryMappedFile;
|
53 |
Buf : array[0..100] of char;
|
54 |
end;
|
55 |
|
56 |
var
|
57 |
frmMain: TfrmMain;
|
58 |
|
59 |
implementation
|
60 |
|
61 |
{$R *.DFM}
|
62 |
|
63 |
|
64 |
procedure TfrmMain.btnOpenMMFClick(Sender: TObject);
|
65 |
begin
|
66 |
AMMFile := TStMemoryMappedFile.Create('', 100, False, True);
|
67 |
if (Assigned(AMMFile)) then begin
|
68 |
btnOpenMMF.Enabled := False;
|
69 |
btnCloseMMF.Enabled := True;
|
70 |
btnUpdate.Enabled := True;
|
71 |
end else
|
72 |
ShowMessage('Unable to create file');
|
73 |
end;
|
74 |
|
75 |
procedure TfrmMain.btnCloseMMFClick(Sender: TObject);
|
76 |
begin
|
77 |
AMMFile.Free;
|
78 |
AMMFile := nil;
|
79 |
btnOpenMMF.Enabled := True;
|
80 |
btnCloseMMF.Enabled := False;
|
81 |
btnUpdate.Enabled := False;
|
82 |
end;
|
83 |
|
84 |
procedure TfrmMain.btnUpdateClick(Sender: TObject);
|
85 |
begin
|
86 |
AMMFile.Seek(0, soFromBeginning);
|
87 |
StrPCopy(Buf, Edit1.Text);
|
88 |
AMMFile.Write(Buf, Length(Edit1.Text)+1);
|
89 |
Label1.Caption := 'Data Size: ' + IntToStr(AMMFile.DataSize);
|
90 |
end;
|
91 |
|
92 |
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
|
93 |
begin
|
94 |
AMMFile.Free;
|
95 |
AMMFile := nil;
|
96 |
end;
|
97 |
|
98 |
end.
|