⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yrpasedit.pas

📁 Object pascal源码,是个非常容易掌握的语法文件。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  else
    Application.BringToFront;
end;

procedure TfrmYourPasEdit.DefaultHandler(var message);
var
  S: string;
begin
  with TMessage(message) do
    if Msg = WM_FINDINSTANCE then
    begin
      Result := MyUniqueConst;
    end
    else if Msg = WM_OPENEDITOR then
    begin
      SetLength(S, MAX_PATH);
      GlobalGetAtomName(WPARAM, PChar(S), MAX_PATH);
      SetLength(S, StrLen(PChar(S)));
      try
        OpenFile(S);
        except on E: Exception do
            raise Exception.Create('Error opening ' + S + ' - ' + E.message);
      end;
    end
    else inherited DefaultHandler(message);
end;


procedure TfrmYourPasEdit.WMNotExists(var Msg: TMessage);
begin
  MessageDlg(Format('File ''%s'' does not exist',[FFileName]), mtError,[mbOK], 0);
end;

procedure TfrmYourPasEdit.LoadFile(FName: string);
begin {Creates a new TabSheet and RichEdit}
  if FileExists(FName) then
  begin
    SCREEN.Cursor := crHourGlass;
    try
      NewTabSheet := TTabSheet.Create(PageControl1);
      NewTabSheet.CAPTION := ExtractFileName(FName);
      NewTabSheet.Hint := FName;
      NewTabSheet.ShowHint := False;
      NewTabSheet.Tag := 1;
      NewTabSheet.PageControl := PageControl1;
      PageControl1.ActivePage := NewTabSheet;
      PageControl1.ActivePage.PopupMenu := pmActivePage;
      PageControl1.ShowHint := False;
      NewRichEdit := TRichEdit.Create(NewTabSheet);
      with NewRichEdit do
      begin
        Parent := NewTabSheet;
        Align := alClient;
        ScrollBars := ssBoth;
        WordWrap := False;
        WantTabs := True;
        HideSelection := False;
        ShowHint := False;
        SetFocus;
      end;
      {sends file through the PasToRtf conversion unit}
      {if a Delphi file, containing too much uncommented text is opened,
                an Invalid String error occurs}
      PasCon := TPasConversion.Create;
      PasCon.UseDelphiHighlighting(3);
      PasCon.LOADFROMFILE(FName);
      PasCon.ConvertReadStream;
      NewRichEdit.Lines.BeginUpdate;
      NewRichEdit.Lines.LoadFromStream(PasCon);
      NewRichEdit.Lines.EndUpdate;
      NewRichEdit.Modified := False;
      NewRichEdit.OnChange := NewRichEditChange;
      NewRichEdit.OnSelectionChange := NewRichEditSelectionChange;
      ActiveControl := NewRichEdit;
      PasCon.Free;
      UpdateControls;
    finally
      SCREEN.Cursor := crDefault;
      SetForegroundWindow(Handle);
    end
  end
  else
  begin
    SetForegroundWindow(Handle);
    PostMessage(Handle, WM_NOTEXISTS, 0, 0);
  end;
end;

procedure TfrmYourPasEdit.LoadFilePT(FName: string);
begin {Loads the file as plain text, used so plain text files can be loaded
					without going through the PasToRtf unit}
  if FileExists(FName) then
  begin
    SCREEN.Cursor := crHourGlass;
    try
      NewTabSheet := TTabSheet.Create(PageControl1);
      NewTabSheet.CAPTION := ExtractFileName(FName);
      NewTabSheet.Hint := FName;
      NewTabSheet.ShowHint := False;
      NewTabSheet.Tag := 0;
      NewTabSheet.PageControl := PageControl1;
      PageControl1.ActivePage := NewTabSheet;
      PageControl1.ActivePage.PopupMenu := pmActivePage;
      PageControl1.ShowHint := False;
      NewRichEdit := TRichEdit.Create(NewTabSheet);
      with NewRichEdit do
      begin
        Parent := NewTabSheet;
        Align := alClient;
        ScrollBars := ssBoth;
        WordWrap := False;
        WantTabs := True;
        ShowHint := False;
        HideSelection := False;
        Lines.LOADFROMFILE(FName);
        Modified := False;
        OnChange := NewRichEditChange;
        OnSelectionChange := NewRichEditSelectionChange;
      end;
      ActiveControl := NewRichEdit;
      NewRichEdit.Modified := False;
      UpdateControls;
    finally
      SCREEN.Cursor := crDefault;
      SetForegroundWindow(Handle);
    end
  end
  else
  begin
    SetForegroundWindow(Handle);
    PostMessage(Handle, WM_NOTEXISTS, 0, 0);
  end;
end;

procedure TfrmYourPasEdit.LoadFileDFM(FName: string);
var
  InStream, OutStream: TMemoryStream;
begin {This uses Delphi's built in ObjectResourceToText procedure to
												convert the Delphi Form file to a plain text format and then opens
                       the file in a new TabSheet/RichEdit}
  if FileExists(FName) then
  begin
    SCREEN.Cursor := crHourGlass;
    try
      NewTabSheet := TTabSheet.Create(PageControl1);
      NewTabSheet.CAPTION := ExtractFileName(FName);
      NewTabSheet.Hint := FName;
      NewTabSheet.ShowHint := False;
      NewTabSheet.Tag := 1;
      NewTabSheet.PageControl := PageControl1;
      PageControl1.ActivePage := NewTabSheet;
      PageControl1.ActivePage.PopupMenu := pmActivePage;
      PageControl1.ShowHint := False;
      NewRichEdit := TRichEdit.Create(NewTabSheet);
      with NewRichEdit do
      begin
        Parent := NewTabSheet;
        Align := alClient;
        ScrollBars := ssBoth;
        WordWrap := False;
        WantTabs := True;
        HideSelection := False;
        ShowHint := False;
        SetFocus;
      end;
      try
        InStream := TMemoryStream.Create;
        InStream.LOADFROMFILE(FName);
        OutStream := TMemoryStream.Create;
        ObjectResourceToText(InStream, OutStream);
        OutStream.Seek(0, 0);
        NewRichEdit.Lines.LoadFromStream(OutStream);
        InStream.Free;
        OutStream.Free;
        except on E: Exception do
            MessageDlg('An error occured during syntax highlighting: ' + E.message + #13 + #10 + #13 + #10 +
            'This usually means that the Delphi file you are' + #13 + #10 +
            ' attempting to open is not a valid Form File (DFM).', mtError,[mbOK], 55);
      end;
      NewRichEdit.Modified := False;
      NewRichEdit.OnChange := NewRichEditChange;
      NewRichEdit.OnSelectionChange := NewRichEditSelectionChange;
      ActiveControl := NewRichEdit;
      UpdateControls;
    finally
      SCREEN.Cursor := crDefault;
      SetForegroundWindow(Handle);
    end
  end
  else
  begin
    SetForegroundWindow(Handle);
    PostMessage(Handle, WM_NOTEXISTS, 0, 0);
  end;
end;

procedure TfrmYourPasEdit.SaveFileToDFM(Filename: string);
var
  OutStream: TFileStream;  
  InStream : TMemoryStream;
  Plaintext: Boolean;      
begin {This uses Delphi's built in ObjectTextToResource procedure to convert the plain text
									file to the Delphi Form file format}
  OutStream := TFileStream.Create(Filename, fmCreate or fmOpenReadWrite);
  InStream := TMemoryStream.Create;
  Plaintext := TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext;
  TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext := True;
  TRichEdit(PageControl1.ActivePage.Controls[0]).Lines.SaveToStream(InStream);
  TRichEdit(PageControl1.ActivePage.Controls[0]).Plaintext := Plaintext;
  InStream.Seek(0, 0);
  ObjectTextToResource(InStream, OutStream); //ObjectTextToResource(TMemoryStream, TFileStream);
  OutStream.Free;
  InStream.Free;
end;

procedure TfrmYourPasEdit.StartNew;
begin {This procedure is not useful in this example app.
						It will be used in a fancy version to allow the option,
           mmStartNew, of starting with a New RichEdit or not
           and is left here because the code works and provides
           the basis for an option if you want to add it.}
  {Create the NewTabSheet}
  NewTabSheet := TTabSheet.Create(PageControl1);
  {Set the NewTabSheet Properties}
  NewTabSheet.CAPTION := 'untitled';
  NewTabSheet.PageControl := PageControl1;
  PageControl1.ActivePage := NewTabSheet;
  PageControl1.ActivePage.PopupMenu := pmActivePage;
  PageControl1.ShowHint := False;
  {creates a NewRichEdit and setsthe NewTabSheet as the parent}
  NewRichEdit := TRichEdit.Create(NewTabSheet);
  NewRichEditSetup(NewRichEdit);
  ActiveControl := NewRichEdit;
  UpdateControls;
end;


procedure TfrmYourPasEdit.FormCreate(Sender: TObject);
begin
  {This had to be done because D3 refused to assign my choice of Application Icon
   		reverting the the old gray default Dellphi icon.}
  Application.ICON := ICON;
  UpdateControls; {Updates MenuItems based on the existance of a TabSheet/RichEdit}
  Application.OnHint := DisplayHint; {Displays hint in the StatusBar}
  Application.OnIdle := AppIdle;
  mmExit.Shortcut := Shortcut(VK_F4,[ssAlt]); //This puts Alt F4 on the menu
end;

procedure TfrmYourPasEdit.FormShow(Sender: TObject);
begin {This is used in the Start With New option}
  mmNewClick(Sender);
  if Assigned(NewRichEdit) then NewRichEdit.SetFocus;
end;

procedure TfrmYourPasEdit.FormDestroy(Sender: TObject);
begin
  SCREEN.OnActiveFormChange := nil;
end;

procedure TfrmYourPasEdit.mmNewClick(Sender: TObject);
begin {This will be used with the Start With New option}
  Inc(Untitleds);
  {Create the NewTabSheet}
  NewTabSheet := TTabSheet.Create(PageControl1);
  {Set the NewTabSheet Properties}
  NewTabSheet.CAPTION := 'untitled' + IntToStr(Untitleds);
  NewTabSheet.Hint := 'untitled' + IntToStr(Untitleds);
  //Sets the Hint to the FileName, which then appears in the StatusBar
  NewTabSheet.PageControl := PageControl1;
  PageControl1.ActivePage := NewTabSheet;
  PageControl1.ActivePage.PopupMenu := pmActivePage;
  PageControl1.ShowHint := False;
  {creates a NewRichEdit and setsthe NewTabSheet as the parent}
  NewRichEdit := TRichEdit.Create(NewTabSheet);
  {Set the NewRichEdit Properties}
  NewRichEditSetup(NewRichEdit);
  ActiveControl := NewRichEdit;
  NewRichEdit.Modified := False;
  UpdateControls;
end;

procedure TfrmYourPasEdit.mmOpenClick(Sender: TObject);
begin {File Open procedure}
  try
    if OpenDialog1.Execute then
    begin
      OpenFile(OpenDialog1.Filename);
    end;
    UpdateControls;
    except on E: Exception do
        raise Exception.Create('Error opening ' + OpenDialog1.Filename + ' - ' + E.message);
  end;
end;

procedure TfrmYourPasEdit.pmaClosePageClick(Sender: TObject);
begin {Close the active page}
  if TRichEdit(PageControl1.ActivePage.Controls[0]).Modified then
  begin
    case MessageDlg('File: ' +
      PageControl1.ActivePage.CAPTION +
        ', has changed. Save now?', mtConfirmation,
        mbYesNoCancel, 0) of
        IDYES:
        begin
          mmSaveClick(Sender);
          PageControl1.ActivePage.Free; //Closes and Frees the ActivePage
          PageControl1.SelectNextPage(False);
          UpdateControls;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -