Solved

Multiple richedits in Tabsheets

Posted on 1997-06-10
1
621 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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