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 |
(*****************************************************************************
|
27 |
|
28 |
This unit shows a basic implementation of the STFIRST Unit methods working
|
29 |
with the StWmDataCopy component. Compile the project and then start it, giving
|
30 |
a text file as part of the command line parameter. For example:
|
31 |
|
32 |
EXFIRST c:\myfiles\afile.txt
|
33 |
|
34 |
You can also start the program without a parameter and use the Load button
|
35 |
to load a text file into the TMemo component
|
36 |
|
37 |
Keep that program running and try to start a second instance, this time
|
38 |
specifying a different file. For example:
|
39 |
|
40 |
EXFIRST c:\myfiles\File2.txt
|
41 |
|
42 |
Note that a second instance of the program does not run but that File2
|
43 |
is loaded into the TMemo component.
|
44 |
|
45 |
*******
|
46 |
WARNING
|
47 |
*******
|
48 |
If running this under Windows 9x, TMemo cannot accept a file larger
|
49 |
than about 32K. If you try to load a file via the command line that is larger,
|
50 |
Delphi raises an execption and the application is terminated. You could avoid
|
51 |
this by modifying the DoFileOpen method to check the size of the file before
|
52 |
it's loaded into the TMemo
|
53 |
|
54 |
******************************************************************************)
|
55 |
|
56 |
|
57 |
unit EXFirstU;
|
58 |
|
59 |
interface
|
60 |
|
61 |
uses
|
62 |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
|
63 |
Dialogs, StdCtrls,
|
64 |
|
65 |
StBase, StwmDCpy;
|
66 |
|
67 |
type
|
68 |
TfrmEXWDC = class(TForm)
|
69 |
StWMDataCopy1: TStWMDataCopy;
|
70 |
Memo1: TMemo;
|
71 |
btnLoadFile: TButton;
|
72 |
OpenDialog1: TOpenDialog;
|
73 |
procedure FormCreate(Sender: TObject);
|
74 |
procedure btnLoadFileClick(Sender: TObject);
|
75 |
procedure StWMDataCopy1DataReceived(Sender: TObject;
|
76 |
CopyData: TCopyDataStruct);
|
77 |
private
|
78 |
{ Private declarations }
|
79 |
public
|
80 |
{ Public declarations }
|
81 |
|
82 |
procedure DoFileOpen(FN : ShortString);
|
83 |
end;
|
84 |
|
85 |
var
|
86 |
frmEXWDC: TfrmEXWDC;
|
87 |
|
88 |
implementation
|
89 |
|
90 |
{$R *.DFM}
|
91 |
|
92 |
procedure TfrmEXWDC.FormCreate(Sender: TObject);
|
93 |
begin
|
94 |
if (ParamCount > 0) then
|
95 |
DoFileOpen(ParamStr(1));
|
96 |
end;
|
97 |
|
98 |
procedure TfrmEXWDC.DoFileOpen(FN : ShortString);
|
99 |
begin
|
100 |
Memo1.Clear;
|
101 |
if (FileExists(FN)) then
|
102 |
Memo1.Lines.LoadFromFile(FN);
|
103 |
end;
|
104 |
|
105 |
procedure TfrmEXWDC.btnLoadFileClick(Sender: TObject);
|
106 |
begin
|
107 |
if OpenDialog1.Execute then
|
108 |
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
|
109 |
end;
|
110 |
|
111 |
procedure TfrmEXWDC.StWMDataCopy1DataReceived(Sender: TObject;
|
112 |
CopyData: TCopyDataStruct);
|
113 |
var
|
114 |
S : string;
|
115 |
I : Longint;
|
116 |
begin
|
117 |
S := String(PChar(CopyData.lpData));
|
118 |
|
119 |
ShowMessage(S);
|
120 |
I := pos(' ', S);
|
121 |
if (I = 0) then
|
122 |
I := pos(#9, S);
|
123 |
if (I > 0) then begin
|
124 |
S := Copy(S, I+1, Length(S));
|
125 |
DoFileOpen(S);
|
126 |
end;
|
127 |
end;
|
128 |
|
129 |
end.
|
130 |
|
131 |
|