Solved

Need a suggestion: to display the data on a standard Delphi component

Posted on 2003-12-12
26
661 Views
Last Modified: 2013-11-23
Hello All!

              I have to display(like a report) some data which generate dynamically from my program. I have some 50 lines of data, including some static text.

       Is there any Delphi control(like panel) where we can design the statictext and keep some texfields for dynamic text.

requirements of a control:
         1. It should be scrolled when the data crosses the boundaries of the control.
         2. The can be printable.

could you suggest a possible standard component to perform my requirement with small example.

regards
rk
0
Comment
Question by:rk001
  • 15
  • 5
  • 3
  • +1
26 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
what about a TRichEdit or TMemo?
0
 

Author Comment

by:rk001
Comment Utility
Hello,

          with TRichEdit and TMemo my requirements wont be solved, because my requirements are below:

 1. i need to format the static text before, for example

     line no:1   Temparature(static text, left 100, Bold properties)       : label1 (in this place dynamic text will be filled)
     line no:2
      ---- and so on-----.(must be scrollable)

2. The content must be printable

3. The content should be saved as a file.

so you suggested controls cant solve my problem.

Please suggest one component, which can solve above my 3 requirements with small example.

regards
rk
0
 

Author Comment

by:rk001
Comment Utility
or please suggest some other possible solution.
0
 
LVL 1

Expert Comment

by:FeralCTO
Comment Utility
If I understand what you're trying to do, it sounds like a case for HTML. You can do any formatting you want, start with a template if appropriate and fill in the dynamic content at runtime, and you have a couple of different options for displaying it.

Regards,

Ron
"FeralCTO"
0
 

Author Comment

by:rk001
Comment Utility
Hello FeralCTO,

            Your suggestion is nice. I am a beginner in programming. I dont know how to communicate HTML or Word document with Delphi, and displying it at the runtime as a Report. Could you help me in making a small example for this complete process.

regards
rk
0
 
LVL 1

Accepted Solution

by:
tormork earned 25 total points
Comment Utility
I agree with kretzschmar about the RichEdit.

procedure Example;
var sl: TStringList;
begin
  // Setting the first 5 charecters green and bold
  RichEdit1.SelStart := 0;
  RichEdit1.SelLength := 5;
  RichEdit1.SelAttributes.Color := clGreen;
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style + [fsBold];

  // show scrollbars
  RichEdit1.ScrollBars := ssBoth;

  // Save to rtf-file
  RichEdit1.Lines.SaveToFile('c:\somefile.rtf');

  // Save to txt file
  sl := TStringList.Create;
  sl.Text := RichEdit1.Lines.Text;
  sl.SaveToFile('c:\somefile.txt');
  sl.destroy;

  // Print
  RichEdit1.Print('Sometitle')
end;


If you set all bevels to bvNone and border to bsNone in the obj. inspector and color := clButton it will even look like a form.
You problably want to set it to read only, since it's a report, but using a RichEdit has an additional advanage in that you can copy and paste to text to another progam.

0
 

Author Comment

by:rk001
Comment Utility
Hello tormork,

     I will try to experiment on your example, and i will respond you soon.

thanks
pvp
0
 

Author Comment

by:rk001
Comment Utility
Hello tormork,

     I will try to experiment on your example, and i will respond you soon.

thanks
rk
0
 

Author Comment

by:rk001
Comment Utility
hello,

         RichEdit working nicely, but i am getting an exception while i am trying to print.

    RichEdit1.print('My Doc');

The Exception: 'External Exception c000008', how can i solve this error.

thanks
rk
0
 

Author Comment

by:rk001
Comment Utility
I am unable to have the Horizontal scroll bar even  i set

RichEdit1.scrollbars := ssBoth;

in my case printing the data is important task. could you say is there any way to show 'Pritn Dialogue' also, which provide printlayout and selecting the printer etc.

could you suggest me how to solve above problems.

thanks
rk
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
why not use quickreport/reportbuilder or any other report-component?
0
 

Author Comment

by:rk001
Comment Utility
Hello,

         i have never worked  with any reporting component(like quickreport).  That is why, to make the report in a easy way i have choosen TRichEdit, for my purpose... as i need to submit my application to my professor soon.

-------------------------------------------------------------------------------
         i explain you the current scenario regarding my reports:

                                 i need to generate 2 reports. for one report, i have a word document(in this i am using MailMerge functionality, with .txt as datasource, and it is writing from delphi app.)
       
                   RichEdit1.Lines.LoadFromFile('c:\report1.rtf')  ---> i formatted everything in the .rtf it self

so it is looking nice, but, RichEdit1.print('rpt'); is generating exception, and  also need 'print setup' dialogue.

Another report i had to generate from code it self..i tried it:
                   
                           RichEdit1.Lines.Add('string1');....like this i am able fill the data. in this case if i want to format some specified line say, line no: 10, to be bold... i dont know how to do it(Richedit1.selstart, with this we have to tell the characters, but i want to tell the line no. to format)

-----------------------------------------------------------------------

if i am able to solve, showing PrintSetup dialogue and Formating specified line with RichEdit, it would be a good solution for me.

You please try to suggest me how to solve above 2 probs. with RichEdit, as it seems i can complete my task quickly.

If you think above 2 functionalities not possible with TRichEdit component, then please provide me few lines of code for qucireport:
             1. How to load a file,(.doc or .rtf) in to quickreport.--> which should be having scroll bar
             2. How to save a report as a file.
and some other important related points.

waiting for your suggestion..........

thanks
rk001




               





       
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rk001
Comment Utility
i solved 'printsetup Dialogue'  using TPrintDialog component.

          now please tell me how to avoid :

                        'External exception C00000008'   exception while printing.

and how to format a specified line in the RichEdit lines.

thanks
pvp
0
 
LVL 1

Expert Comment

by:tormork
Comment Utility

RichEdit1.scrollbars := ssBoth;
The reason for the missing scrollbars is problably that you have WordWrap=true. If WordWrap=false the lines can continue past the right margin (Well there is no rigth margin)

With wordwrap=false it is also easier to calculate where each line start by accumulating Lengt(RichEdit1.Lines[0])+Lengt(RichEdit1.Lines[1])... You can then use this as RichEdit1.SelStart(Maybe you'll have to add 1 or 2 to each line to accomodate linefeed, I can't remeber)

I do not know why you get 'External exception C00000008', sorry :)
0
 

Author Comment

by:rk001
Comment Utility
Thanks tormork,

        i think  'External exception C00000008' this exception is due to printer driver problem. i will solve it.

could you say how to give left margin to the current line in RichEdit,
       eg:
                     line1
                         line2
                     line3

these lines will be added dynamically. here for line2, it needs some left margin.

is there any thing like
        Richedit1,selAttributes.left := 10; ---> i know this is wrong statement :) just to get an idea

thanks
pvp
0
 
LVL 1

Expert Comment

by:tormork
Comment Utility
Yea, when you selstart is in a paragraph you can use:
  RichEdit1.Paragraph.FirstIndent  := 10;
  RichEdit1.Paragraph.LeftIndent := 20;
The first line will have an indent of 10 and the rest 20 px
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
look at

richedit1.Paragraph.LeftIndent := whatever
0
 

Author Comment

by:rk001
Comment Utility
Hello,

NOT LOADING THE UPDATED FILE
           I have a new problem with RichEdit:

procedure btnclick()
begin
update(fileaname.rtf); //this is my procedure, here file.rtf is updated

//ReportsDisp --> TRcihEdit

ReportsDisp.ReadOnly := true;
ReportsDisp.Clear;
ReportsDisp.Lines.Clear;
ReportsDisp.ReadOnly := false;
ReportsDisp.Lines.LoadFromFile(filename.rtf);
ReportsDisp.ReadOnly := true;
end;

Even though i have updated the file.rtf successfully with new data, Richedit is not showing the updated file data, but it is showing previous data.

could you suggest me how to solve this problem

thanks
pvp1
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
what does
update(fileaname.rtf);
?
0
 

Author Comment

by:rk001
Comment Utility
Hello  kretzschmar,

        update(fileaname.rtf);  in this procedure call, i am updating a DataSource(it is a text file, souce.txt). And using this DataSource and MailMerge concept i am making a new updated .rtf file.(previously for this file the datasouce has been opend with .txt file).

after update(fileaname.rtf); procedure call only i am tying to load the .rtf file into the RichEdit control. But it is not displying the updated data.

Note: when i am trying to open this particular .rtf file to be loaded in to the RichEdit control, manually then i found data has been modified.

please tell me how can i solve this problem.

thanks
pvp1
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 25 total points
Comment Utility
??
usual i would guess
- the file is not updated
or
- you load the wrong file (check the filename)

otherwise, maybe the os gets an older version from cache
(guess that isn't it)

meikl ;-)
0
 

Author Comment

by:rk001
Comment Utility
Hello  kretzschmar,

           one more point when i open this updated .rtf file manuall and save it, and then if i execute my application RichEdit is loading the updated .rtf file. i am unable to understand why it is happening.

please give me a suggestion.

thanks
0
 

Author Comment

by:rk001
Comment Utility
one more point... the .rtf has been created using office 97 as the application should work for both with office 97 and office 2000. if you want i can show the source code for opening the data source for the rtf file.

             
0
 

Author Comment

by:rk001
Comment Utility
Hello ,

if there any possibility of converting .doc file to .rtf before  ReportsDisp.Lines.LoadFromFile(filename.rtf); statement. If i am able to do this i may solve my problem.

thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now