📄 yrpasedit.pas
字号:
end;
IDNO:
begin
PageControl1.ActivePage.Free; //Closes and Frees the ActivePage
PageControl1.SelectNextPage(False);
UpdateControls;
end;
end;
end else
begin
PageControl1.ActivePage.Free; //Closes and Frees the ActivePage
PageControl1.SelectNextPage(False);
UpdateControls;
end;
end;
procedure TfrmYourPasEdit.mmFindClick(Sender: TObject);
begin
with TRichEdit(PageControl1.ActivePage.Controls[0]) do
begin
if (SelLength > 0) and (SelLength < 30) then
FindDialog1.FindText := SelText;
FindDialog1.Execute;
end;
end;
{I think this came from a Neil Rubenking example}
procedure TfrmYourPasEdit.FindDialog1Find(Sender: TObject);
const STypes: array[Boolean, Boolean] of TSearchTypes =
(([],[stMatchCase]),
([stWholeWord],[stWholeWord, stMatchCase]));
var Start, len, loc: Integer;
begin
Start := TRichEdit(PageControl1.ActivePage.Controls[0]).SelStart + TRichEdit(PageControl1.ActivePage.Controls[0]).SelLength;
len := TRichEdit(PageControl1.ActivePage.Controls[0]).GetTextLen - Start;
with Sender as TFindDialog do
loc := TRichEdit(PageControl1.ActivePage.Controls[0]).FindText(FindText, Start, len,
STypes[frWholeWord in Options, frMatchCase in Options]);
if loc = -1 then
MessageBeep(MB_ICONSTOP)
{I would like to have a message popup saying that no other instances of the
chosen word was found, but it seems to cause some
functions to fail, like ReplaceAll}
else
begin
TRichEdit(PageControl1.ActivePage.Controls[0]).SelStart := loc;
TRichEdit(PageControl1.ActivePage.Controls[0]).SelLength :=
Length((Sender as TFindDialog).FindText);
end;
FindDialog1.FindText := (Sender as TFindDialog).FindText;
ReplaceDialog1.FindText := FindDialog1.FindText;
end;
procedure TfrmYourPasEdit.mmFindAgainClick(Sender: TObject);
begin
if Assigned(PageControl1.ActivePage) then
FindDialog1Find(FindDialog1);
end;
procedure TfrmYourPasEdit.mmReplaceClick(Sender: TObject);
begin
with TRichEdit(PageControl1.ActivePage.Controls[0]) do
begin
if (SelLength > 0) and (SelLength < 30) then
ReplaceDialog1.FindText := SelText;
ReplaceDialog1.Execute;
end;
end;
procedure TfrmYourPasEdit.ReplaceDialog1Replace(Sender: TObject);
begin
ENABLED := False;
SCREEN.Cursor := crHourGlass;
TRichEdit(PageControl1.ActivePage.Controls[0]).Perform(WM_SETREDRAW, 0, 0);
try
with Sender as TReplaceDialog do
while True do
begin
if TRichEdit(PageControl1.ActivePage.Controls[0]).SelText <> FindText then
FindDialog1Find(Sender);
if TRichEdit(PageControl1.ActivePage.Controls[0]).SelLength = 0 then Break;
TRichEdit(PageControl1.ActivePage.Controls[0]).SelText := ReplaceText;
if not (frReplaceAll in Options) then Break;
Application.ProcessMessages;
if Application.Terminated then Break;
end;
finally
ENABLED := True;
SCREEN.Cursor := crDefault;
TRichEdit(PageControl1.ActivePage.Controls[0]).Perform(WM_SETREDRAW, 1, 0);
TRichEdit(PageControl1.ActivePage.Controls[0]).Refresh;
end;
end;
{OPTIONS}
procedure TfrmYourPasEdit.mmMultiLineClick(Sender: TObject);
begin {display the TabSheets in a MultiLine}
mmMultiLine.checked := not mmMultiLine.checked;
if mmMultiLine.checked then
PageControl1.MultiLine := True
else
PageControl1.MultiLine := False;
end;
procedure TfrmYourPasEdit.mmStatusBarClick(Sender: TObject);
begin {Toggle StatusBar visible}
mmStatusBar.checked := not mmStatusBar.checked;
StatusBar.Visible := mmStatusBar.checked;
end;
procedure TfrmYourPasEdit.DisplayHint(Sender: TObject);
begin {This also displays the file path when the cursor is in the RichEdit}
StatusBar.Panels[6].Text := Application.Hint;
end;
procedure TfrmYourPasEdit.mmExitClick(Sender: TObject);
begin
CLOSE; {Hmm, I wonder what this does?:-}
end;
procedure TfrmYourPasEdit.mmEditClick(Sender: TObject);
begin {Enables Edits commands according to availability of a selected item}
if Assigned(PageControl1.ActivePage) then
TRichEdit(PageControl1.ActivePage.Controls[0]).SetFocus else Exit;
mmPaste.ENABLED := Clipboard.HasFormat(CF_TEXT);
mmUndo.ENABLED := TRichEdit(PageControl1.ActivePage.Controls[0]).Perform(EM_CANUNDO, 0, 0) <> 0;
mmCut.ENABLED := TRichEdit(PageControl1.ActivePage.Controls[0]).SelLength > 0;
mmCopy.ENABLED := TRichEdit(PageControl1.ActivePage.Controls[0]).SelLength > 0;
mmFindAgain.ENABLED := FindDialog1.FindText <> '';
end;
{These are the Edit MenuItems}
procedure TfrmYourPasEdit.mmSelectAllClick(Sender: TObject);
begin
TRichEdit(PageControl1.ActivePage.Controls[0]).SelectAll;
end;
procedure TfrmYourPasEdit.mmUndoClick(Sender: TObject);
begin
TRichEdit(PageControl1.ActivePage.Controls[0]).Perform(EM_UNDO, 0, 0);
end;
procedure TfrmYourPasEdit.mmCutClick(Sender: TObject);
begin
TRichEdit(PageControl1.ActivePage.Controls[0]).CutToClipboard;
end;
procedure TfrmYourPasEdit.mmCopyClick(Sender: TObject);
begin
TRichEdit(PageControl1.ActivePage.Controls[0]).CopyToClipboard;
end;
procedure TfrmYourPasEdit.mmPasteClick(Sender: TObject);
begin
TRichEdit(PageControl1.ActivePage.Controls[0]).PasteFromClipboard;
end;
procedure TfrmYourPasEdit.mmPrintClick(Sender: TObject);
begin {Performs the basic RichEdit printing}
if Assigned(NewRichEdit) then
with PrintDialog do
if Execute then
begin
NewRichEdit.Print(SaveDialog1.Filename);
end
else
Exit;
end;
procedure TfrmYourPasEdit.mmPrinterSetupClick(Sender: TObject);
begin {Opens the Printer Setup dialog}
with PrinterSetupDialog do Execute;
end;
procedure TfrmYourPasEdit.mmAboutClick(Sender: TObject);
begin {Shows the AboutBox}
Application.CreateForm(TfrmAbout, frmAbout);
frmAbout.ShowModal;
frmAbout.Release;
end;
procedure TfrmYourPasEdit.mmFileClick(Sender: TObject);
begin {Enables the Save MenuItem if RichEdit is Modified}
mmSave.ENABLED := (Assigned(PageControl1.ActivePage)) and (TRichEdit(PageControl1.ActivePage.Controls[0]).Modified);
end;
procedure TfrmYourPasEdit.mmSaveClick(Sender: TObject);
var {Saves the file based on which file extension is selected}
Plaintext: Boolean;
begin
if not FileExists(PageControl1.ActivePage.Hint) then
mmSaveAsClick(Sender) else
begin {if it is NOT a Delphi Form file}
if (UpperCase(ExtractFileExt(PageControl1.ActivePage.Hint)) <> '.DFM') and
(UpperCase(ExtractFileExt(PageControl1.ActivePage.Hint)) <> '.~DF') then
begin {it gets saved as a plain text file}
Plaintext := TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext;
TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext := (UpperCase(ExtractFileExt(PageControl1.ActivePage.Hint)) <> '.RTF');
TRichEdit(PageControl1.ActivePage.Controls[0]).Lines.SaveToFile(PageControl1.ActivePage.Hint);
TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext := Plaintext;
TRichEdit(PageControl1.ActivePage.Controls[0]).Modified := False;
PageControl1.ActivePage.CAPTION := ExtractFileName(PageControl1.ActivePage.Hint);
end else
begin {if it is a DFM or ~DF file, it gets saved as a DFM}
SaveFileToDFM(PageControl1.ActivePage.Hint);
TRichEdit(PageControl1.ActivePage.Controls[0]).Modified := False;
PageControl1.ActivePage.CAPTION := ExtractFileName(PageControl1.ActivePage.Hint);
end;
end;
end;
procedure TfrmYourPasEdit.mmSaveAsClick(Sender: TObject);
var
Plaintext: Boolean;
begin
if SaveDialog1.Execute then
begin
if (UpperCase(ExtractFileExt(PageControl1.ActivePage.Hint)) <> '.DFM') and
(UpperCase(ExtractFileExt(PageControl1.ActivePage.Hint)) <> '.~DF') then
begin
Plaintext := TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext;
TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext := SaveDialog1.FilterIndex <> 2;
TRichEdit(PageControl1.ActivePage.Controls[0]).Lines.SaveToFile(SaveDialog1.Filename);
TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext := Plaintext;
PageControl1.ActivePage.CAPTION := ExtractFileName(SaveDialog1.Filename);
PageControl1.ActivePage.Hint := SaveDialog1.Filename;
TRichEdit(PageControl1.ActivePage.Controls[0]).Modified := False;
end else
begin
SaveFileToDFM(SaveDialog1.Filename);
PageControl1.ActivePage.CAPTION := ExtractFileName(SaveDialog1.Filename);
PageControl1.ActivePage.Hint := SaveDialog1.Filename;
TRichEdit(PageControl1.ActivePage.Controls[0]).Modified := False;
end;
end;
end;
procedure TfrmYourPasEdit.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var {Checks if RichEdit has been Modified before closing}
I: Integer;
begin
for I := 0 to PageControl1.PageCount - 1 do
begin
if TRichEdit(PageControl1.Pages[I].Controls[0]).Modified then
case MessageDlg('File: ' +
PageControl1.Pages[I].CAPTION +
', has changed. Save now?', mtConfirmation,
mbYesNoCancel, 0) of
IDYES: mmSaveClick(Sender);
IDNO:;
IDCANCEL: CanClose := False;
end;
end;
end;
procedure TfrmYourPasEdit.mmCloseAllClick(Sender: TObject);
var {Close All pages}
I: Integer;
begin
for I := PageControl1.PageCount - 1 downto 0 do
begin
PageControl1.ActivePage := PageControl1.Pages[I];
pmaClosePageClick(Sender);
end;
end;
procedure TfrmYourPasEdit.mmSaveAllClick(Sender: TObject);
var {Save All modified RichEdits}
I: Integer;
begin
for I := PageControl1.PageCount - 1 downto 0 do
begin
PageControl1.ActivePage := PageControl1.Pages[I];
mmSaveClick(Sender);
end;
end;
procedure TfrmYourPasEdit.NewRichEditChange(Sender: TObject);
begin {Places an asterisk on TabSheet's tab which contains a Modified RichEdit}
if Assigned(PageControl1.ActivePage) and
(TRichEdit(PageControl1.ActivePage.Controls[0]).Modified) and
not (PageControl1.ActivePage.CAPTION[Length(PageControl1.ActivePage.CAPTION)] = '*') then
PageControl1.ActivePage.CAPTION := PageControl1.ActivePage.CAPTION + '*';
end; //This is where Closing pages causes the Access Violation
procedure TfrmYourPasEdit.NewRichEditSelectionChange(Sender: TObject);
var {A Neil Rubenking example of putting the cursor position into the StatusBar}
RO, CO: Integer;
begin
with Sender as TCustomEdit do
begin
RO := Perform(EM_LINEFROMCHAR, SelStart, 0);
CO := SelStart - Perform(EM_LINEINDEX, RO, 0);
StatusBar.Panels[0].Text := FormatFloat('0,', RO + 1);
StatusBar.Panels[1].Text := FormatFloat('0,', CO + 1);
StatusBar.Panels[2].Text := FormatFloat(',0', SelStart);
end;
end;
initialization {Used in the file association and running instance code}
WM_FINDINSTANCE := RegisterWindowMessage('Editor: find previous instance');
if WM_FINDINSTANCE = 0 then raise Exception.Create('Initialization failed');
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -