home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
PROGRAM
/
DELPHI
/
9703
/
MEMOFORM.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1996-12-27
|
8KB
|
308 lines
unit memoform;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, ComCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
N1: TMenuItem;
PrintSetup1: TMenuItem;
Print1: TMenuItem;
N2: TMenuItem;
SaveAs1: TMenuItem;
Save1: TMenuItem;
Open1: TMenuItem;
New1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
HowtoUseHelp1: TMenuItem;
SearchforHelpOn1: TMenuItem;
Contents1: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
RichEdit1: TRichEdit;
Edit1: TMenuItem;
Replace1: TMenuItem;
Find1: TMenuItem;
N4: TMenuItem;
Paste1: TMenuItem;
Copy1: TMenuItem;
Cut1: TMenuItem;
N5: TMenuItem;
Undo1: TMenuItem;
PrintDialog1: TPrintDialog;
PrinterSetupDialog1: TPrinterSetupDialog;
FindDialog1: TFindDialog;
ReplaceDialog1: TReplaceDialog;
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
procedure Open1Click(Sender: TObject);
procedure SaveAs1Click(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Exit1Click(Sender: TObject);
procedure Undo1Click(Sender: TObject);
procedure Cut1Click(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Paste1Click(Sender: TObject);
procedure Print1Click(Sender: TObject);
procedure PrintSetup1Click(Sender: TObject);
procedure Find1Click(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
procedure Replace1Click(Sender: TObject);
procedure ReplaceDialog1Replace(Sender: TObject);
private
{ Private 宣言 }
public
FileName: string;
function VerifyModified: Boolean;
end;
var
Form1: TForm1;
implementation
uses memoabt;
{$R *.DFM}
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
if VerifyModified then
begin
if OpenDialog1.Execute then
begin
FileName := OpenDialog1.FileName;
Caption := 'メモ帳 - ' + FileName;
RichEdit1.Lines.LoadFromFile(FileName);
RichEdit1.Modified := False;
end;
end;
end;
procedure TForm1.SaveAs1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
FileName := SaveDialog1.FileName;
Caption := 'メモ帳 - ' + FileName;
RichEdit1.Lines.SaveToFile(FileName);
RichEdit1.Modified := False;
end
else
Abort;
end;
procedure TForm1.New1Click(Sender: TObject);
begin
if VerifyModified then
begin
FileName := 'Untitled';
Caption := 'メモ帳 - ' + FileName;
RichEdit1.Lines.Clear;
RichEdit1.Modified := False;
end;
end;
procedure TForm1.About1Click(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
if FileName = 'Untitled' then
SaveAs1Click(Sender)
else
begin
RichEdit1.Lines.SaveToFile(FileName);
RichEdit1.Modified := False;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FileName := 'Untitled';
Caption := 'メモ帳 - ' + FileName;
end;
function TForm1.VerifyModified: Boolean;
var
Ret: Word;
begin
Result := True;
if RichEdit1.Modified then
begin
Ret := MessageDlg('テキストは変更されています。保存しますか?',
mtConfirmation, mbYesNoCancel, 0);
case Ret of
mrYes: Save1Click(Self);
mrNo: ;
mrCancel: Result := False;
end;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := VerifyModified;
end;
procedure TForm1.Undo1Click(Sender: TObject);
begin
RichEdit1.Perform(EM_UNDO, 0, 0);
end;
procedure TForm1.Cut1Click(Sender: TObject);
begin
RichEdit1.CutToClipboard;
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
RichEdit1.CopyToClipboard;
end;
procedure TForm1.Paste1Click(Sender: TObject);
begin
RichEdit1.PasteFromClipboard;
end;
procedure TForm1.Print1Click(Sender: TObject);
begin
if PrintDialog1.Execute then
RichEdit1.Print(FileName);
end;
procedure TForm1.PrintSetup1Click(Sender: TObject);
begin
PrinterSetupDialog1.Execute;
end;
procedure TForm1.Find1Click(Sender: TObject);
begin
FindDialog1.Execute;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
Op: TSearchTypes;
Pos, Len, Scrl: Integer;
begin
with Sender as TFindDialog do
begin
{ オプションの設定 }
Op := [];
if frMatchCase in Options then
Include(Op, stMatchCase);
if frWholeWord in Options then
Include(Op, stWholeWord);
{ テキストの最大長を調べる }
Len := GetWindowTextLength(RichEdit1.Handle);
{ 文字列検索 }
Pos := RichEdit1.FindText(FindText, RichEdit1.SelStart + 1, Len, Op);
{ 検索結果 }
if Pos > 0 then
begin
RichEdit1.SelStart := Pos;
RichEdit1.SelLength := Length(FindText);
{ カーソルが見える位置にスクロールする }
Scrl := RichEdit1.Perform(EM_LINEFROMCHAR, Pos, 0)
- RichEdit1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0);
RichEdit1.Perform(EM_LINESCROLL, 0, Scrl);
end
else
ShowMessage('''' + FindText + ''' not found');
CloseDialog;
end;
end;
procedure TForm1.Replace1Click(Sender: TObject);
begin
ReplaceDialog1.Execute;
end;
procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
var
Op: TSearchTypes;
Pos, SavePos, Len, Scrl: Integer;
begin
with ReplaceDialog1 do
begin
{ オプションの設定 }
Op := [];
if frMatchCase in Options then
Include(Op, stMatchCase);
if frWholeWord in Options then
Include(Op, stWholeWord);
{ テキストの最大長を調べる }
Len := GetWindowTextLength(RichEdit1.Handle);
if frReplaceAll in Options then
begin
{ 全置換の場合 }
Pos := RichEdit1.SelStart;
SavePos := Pos;
repeat
Pos := RichEdit1.FindText(FindText, Pos + 1, Len, Op);
if Pos > 0 then
begin
RichEdit1.SelStart := Pos;
RichEdit1.SelLength := Length(FindText);
RichEdit1.SelText := ReplaceText;
end;
until Pos < 0;
{ カーソルは最初の位置に戻す }
RichEdit1.SelStart := SavePos;
end
else
begin
{ 置換して次へ }
if (frMatchCase in Options)
and (CompareStr(RichEdit1.SelText, FindText) = 0) then
RichEdit1.SelText := ReplaceText
else if not (frMatchCase in Options)
and (CompareText(RichEdit1.SelText, FindText) = 0) then
RichEdit1.SelText := ReplaceText;
Pos := RichEdit1.FindText(FindText, RichEdit1.SelStart + 1, Len, Op);
if Pos > 0 then
begin
RichEdit1.SelStart := Pos;
RichEdit1.SelLength := Length(FindText);
Scrl := RichEdit1.Perform(EM_LINEFROMCHAR, Pos, 0)
- RichEdit1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0);
RichEdit1.Perform(EM_LINESCROLL, 0, Scrl);
end
else
ShowMessage('''' + FindText + ''' not found');
end;
{ CloseDialog; }
end;
end;
end.