Solved

Multiple richedits in Tabsheets

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now