Solved

Multiple richedits in Tabsheets

Posted on 1997-06-10
1
622 Views
Last Modified: 2013-11-22
I am building a RichEdit editor with this difference.

The editor consists of a tabsheet with a richedit component in it.
at startup only one tabsheet is active and one richedit.

but this is what I want, if I click 'New' or 'Open', a new tabsheet should appear with a new richedit component in it that should become the active field.


the caption of the tabsheet has to be the name of the opened file and if I want to Copy, cut or do some other operation on it it has to work on all richedit fields.
and if I wish to save something it has to be the Active tab with the active Richedit component.

so far I have this.
===================

1) Tabsheet at startup but the caption remains 'tabsheet1'    and the following code for creating a new tabsheet:

       with TTabSheet.Create(Self) do
       begin
        Caption := 'OpenDialog1.FileName';
        PageControl := PageControl1;

   the openDialog1.Filename doesn't work, what do I do to    make the caption to read the filename.
   and I am missing the code for creating a new richedit    field.

2) For Opening a File :

      if OpenDialog1.Execute then
      RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);
   
   ofcourse this is only valid for richedit1, how do I make    a new tabsheet here with a new richedit field and fill it    with the opened text file and if the first Richedit    field is still empty to fill that one first.

3) For editing such as COPY,CUT,Paste I have code like this:

     RichEdit1.CopyToClipBoard;   etc...

   ofcourse this is only valid for richEdit1 and I need more    richEdit components. so what do I have to do here, so    that it works on all richedit fields.


4) and also I am using a component called PageSetupDialog,    which is used by Windows for formatting text before    printing.
   I used following code to try printing:

     if PageSetupDialog1.Execute then
     RichEdit1.Print(OpenDialog1.FileName);

   But when printing there are no margins although I    selected them in the PageSetupDialog, and the Microsoft    developer help file is a mystery to me, so what needs to    be changed here?


Please explain in detail, I'm pretty new to delphi.
thanks
0
Comment
Question by:hellfire052497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 100 total points
ID: 1336941
This code will do (very basically) what you want:
(Wrote it very fast and tested it even faster, so no guarantees ;^)

unit Main;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, ComCtrls;

type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    N1: TMenuItem;
    Save1: TMenuItem;
    Open1: TMenuItem;
    Edit1: TMenuItem;
    Paste1: TMenuItem;
    Copy1: TMenuItem;
    Cut1: TMenuItem;
    OpenDialog1: TOpenDialog;
    PageControl1: TPageControl;
    Close1: TMenuItem;
    procedure Open1Click(Sender: TObject);
    procedure Cut1Click(Sender: TObject);
    procedure Copy1Click(Sender: TObject);
    procedure Paste1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure Save1Click(Sender: TObject);
    procedure Close1Click(Sender: TObject);
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.Open1Click(Sender: TObject);
var
  TabSheet: TTabSheet;
begin
  if OpenDialog1.Execute then
  begin
    TabSheet             := TTabSheet.Create(Self);
    TabSheet.Caption     := LowerCase(OpenDialog1.Filename);
    TabSheet.PageControl := PageControl1;
    with TRichEdit.Create(Self) do
    begin
      Parent := TabSheet;
      Lines.LoadFromFile(OpenDialog1.Filename);
    end;
    PageControl1.ActivePage := TabSheet;
    Save1.Enabled := True;
  end;
end;

procedure TMainForm.Cut1Click(Sender: TObject);
begin
  if (ActiveControl is TRichEdit)
  then (ActiveControl as TRichEdit).CutToClipboard
end;

procedure TMainForm.Copy1Click(Sender: TObject);
begin
  if (ActiveControl is TRichEdit)
  then (ActiveControl as TRichEdit).CopyToClipboard
end;

procedure TMainForm.Paste1Click(Sender: TObject);
begin
  if (ActiveControl is TRichEdit)
  then (ActiveControl as TRichEdit).PasteFromClipboard
end;

procedure TMainForm.Exit1Click(Sender: TObject);
begin
  Close
end;

procedure TMainForm.Save1Click(Sender: TObject);
begin
  with PageControl1.ActivePage
  do (Controls[0] as TRichEdit).Lines.SaveToFile(Caption)
end;

procedure TMainForm.Close1Click(Sender: TObject);
begin
  PageControl1.ActivePage.Free;
  PageControl1.SelectNextPage(False);
end;

end.

I have already answered your last question in another question.
Look in the accepted answer section.

Enjoy!

/// John

0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month4 days, 6 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question