Solved

Inserting text into an app.

Posted on 1998-02-23
7
134 Views
Last Modified: 2010-08-05
I am writing an application which needs to act as a
text editor, but also be able to insert specific lines of
text when a menu item is selected. The inserted text needs
to then behave as if it were entered by the user ie. the
user should then be able to delete, add to, or alter the
text in any way. Anyone know how?
afterwards if neccesary.
0
Comment
Question by:kh5395
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
inter earned 20 total points
ID: 1359727
1 - Just open a new project
2 - Place a button and TMemo component on form
3 - dblclick on button. and write the following in between
    Memo1.Lines.Add('This is the interted line');
4 - Run the project
5 - type in some lines in memo
6 - press the button
7 - For doing this by menu write down the same or similiar code to the menus click method normally

Is it OK
Igor
0
 

Author Comment

by:kh5395
ID: 1359728
Igor,
     That's exactly what I needed to do. However, my problem is
that I have several dialog boxes. These all need to take data
from the user and then display a piece of text.
     e.g. one box asks the user to choose a style, each of which
is listed as a radio box. The dialog box unit then needs to
display this information on the TMemo. My problem now is that
I can't get at the TMemo because it is in the main unit. Could
you tell me how to do this? I tried putting the main unit in the
'uses' declaration, but it says this is a circular statement.
I would really appreciate your help.
Thanks again,
Nik



0
 

Author Comment

by:kh5395
ID: 1359729
Igor,
     That's exactly what I needed to do. However, my problem is
that I have several dialog boxes. These all need to take data
from the user and then display a piece of text.
     e.g. one box asks the user to choose a style, each of which
is listed as a radio box. The dialog box unit then needs to
display this information on the TMemo. My problem now is that
I can't get at the TMemo because it is in the main unit. Could
you tell me how to do this? I tried putting the main unit in the
'uses' declaration, but it says this is a circular statement.
I would really appreciate your help.
Thanks again,
Nik



0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:kh5395
ID: 1359730
Igor,
     That's exactly what I needed to do. However, my problem is
that I have several dialog boxes. These all need to take data
from the user and then display a piece of text.
     e.g. one box asks the user to choose a style, each of which
is listed as a radio box. The dialog box unit then needs to
display this information on the TMemo. My problem now is that
I can't get at the TMemo because it is in the main unit. Could
you tell me how to do this? I tried putting the main unit in the
'uses' declaration, but it says this is a circular statement.
I would really appreciate your help.
Thanks again,
Nik



0
 
LVL 5

Expert Comment

by:inter
ID: 1359731
Try forming a uses clause in the implementation that is

unit2

interface
...

implementation

uses
  Unit1;
...

Ok?
Igor
0
 

Author Comment

by:kh5395
ID: 1359732
Igor,

I've tried that, but it doesn't seem to work :

unit Main;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Menus, StdCtrls, docclsdg;

type
  TMainForm = class(TForm)
    ...
    ...
    ...

    procedure RunLaTeX1Click(Sender: TObject);
    procedure Class1Click(Sender: TObject);
    procedure InsertText(var S: String);
 
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.RunLaTeX1Click(Sender: TObject);
begin
WinExec('Latex',SW_SHOWMAXIMIZED);
end;

procedure TMainForm.Class1Click(Sender: TObject);
begin
     docclassdlg.ShowModal;
end;

procedure TMainForm.InsertText(var S: string);
begin
     MainForm.EditPad.Lines.Add(S);
end;
end.

****************

unit Docclsdg;

interface

uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  StdCtrls, ExtCtrls;

type
  Tdocclassdlg = class(TForm)
    OKBtn: TBitBtn;
    CancelBtn: TBitBtn;
    HelpBtn: TBitBtn;
    Bevel1: TBevel;
    RadioGroup1: TRadioGroup;
    Label1: TLabel;
    procedure OKBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  docclassdlg: Tdocclassdlg;

implementation
uses
    Main;
{$R *.DFM}

procedure Tdocclassdlg.OKBtnClick(Sender: TObject);
begin
     InsertText('Inserted Text');
end;

end.


I get a syntax error when it tries to run InsertText. Any idea
why?
Thanks, Nik.

0
 
LVL 5

Expert Comment

by:inter
ID: 1359733
Hi,

When you call one class method from another, you should specify the class name before the method just as refering a member of a record so

InsertText('Inserted Text') should be
MainForm.InsertText('Inserted Text') is this ok?

Igor
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

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 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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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