Solved

Multiple richedits in Tabsheets

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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