Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple richedits in Tabsheets

Posted on 1997-06-10
1
Medium Priority
?
625 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 400 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

885 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