Solved

Printing Text Data from a TMemofield ??

Posted on 2000-04-11
14
422 Views
Last Modified: 2010-04-04
Hi,
   Last week I asked a question about Memo components (http://www1.experts-exchange.com/Computers/Programming/Windows/Delphi/Q_10323085.html) and I was given the direction of using a RichEdit component for better formatting. This all worked fine and the data is saved to a TMemofield in a Dbase for Windows table.

My question is that I want to output the data from the TMemofield onto a report and I am currently outputting to an Image canvas as I wrote my own preview screen for the reports. This has to stay the same as it is part of a much larger program and it allows me to format the reports exactly the way I want. Now the data I currently load from the TMemofield shows Unicode characters on the Image canvas and also the Printer Canvas when printing.

To actually get the data I load the data to a hidden RichEdit component and it loads that fine. I cannot use the RichEdit.Print method as I want to format other items onto the report and I need the freedom to do this. Does anyone know how I can get the data from the TMemofield and View and Print it without the Unicode characters ?? I know it is a bit tricky but I will also keep perservering to see if I can solve it.

I use this code currently

        RichLines := RichEdit1.Lines.Count;
        For i := 0 to RichLines - 1 do
        begin
          ViewImage.Canvas.TextOut(50+(Index*700),700+(i*30),RichEdit1.Lines[i]);
        end;

I have tried quite a few settings to no avail and you may suggest something I have tried but any comments will be appreciated.

Thanks,
 
 WESTY :)
0
Comment
Question by:westy100697
  • 9
  • 2
  • 2
  • +1
14 Comments
 

Author Comment

by:westy100697
ID: 2705746
The problem character is a Tab. The Unicode equivalent is a small box and it doesn't look real good on a report.


WESTY .
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2705896
One way would be to find the tab chars in the string and process them by chopping off the text up to the tab and displaying that, then taking the remainder of the string and display it at an appropriate place after the first piece depending on how you need to process your tabs (do this iteratively/recursively) until the string is empty.

You can find out the width of the displayed string by using Canvas.TextWidth...

Cheers,

Raymond.

0
 

Author Comment

by:westy100697
ID: 2705908
rwilson,
        You must be psychic! I am just doing that now. Probably the only way to do eh. I am using StrPos and StrScan to determine positioning. Probably have to delete this Q now unless there is a simpler way.

WESTY :)
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:westy100697
ID: 2705910
I will award you some points however for taking the time.

Cheers,

 WESTY :
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2706000
Thanks Westy.

One point: you should use UniCode aware versions of StrPos and StrScan. We use MBCS and would use ANSIStrPos et al - I am not sure if the same applies to UniCode though...

Cheers,

Raymond.
0
 

Author Comment

by:westy100697
ID: 2706076
Thanks Raymond but I have nailed it. Always the way isn't it. I will delete this Q and pop a 50 pointer up for you to get. Thanks for the help.

WESTY :)
     
0
 
LVL 9

Accepted Solution

by:
ITugay earned 200 total points
ID: 2706852
hi westy!
It's me again. Did you know about API function DrawText?

-------- Delphi help------
The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth).
.....
DT_EXPANDTABS      Expands tab characters. The default number of characters per tab is eight.
.....
---------end of help-----


Would you like a sample code of using it? (there are lot of points, if you need, just let me know).
-----
Igor.
0
 

Author Comment

by:westy100697
ID: 2707437
Hi Igor,
        Unfortunately that gives me the same problem as before as DrawText requires a PChar and not a string and therefore I have those silly Unicode boxes throughout the text. Not a bad answer though. It doesn't matter even reading directly from the TMemofield I still get the same problem when the text is shown on the screen or it is printed.
The only way I have been able to overcome it was step through each of the lines and replace the #9 tabs with a blank character. Not ideal but it at least prints and views without those pesky characters in the text. I will probably give you some points also just for the effort.

Thanks,

WESTY :)
0
 

Author Comment

by:westy100697
ID: 2707461
Igor,
     My apologies on that last comment. I just re-read your comment and it said DT_EXPANDTABS. I was trying DT_LEFT. Sorry about that but your answer is very good. Lock the question and the points are yours. I will also pop a question up for rwilson and his comments.

Thanks to u 2,

WESTY :)
0
 

Author Comment

by:westy100697
ID: 2707463
Thanks again Igor. You are making a habit of answering my questions. That is good as I get a quick response every time here.

WESTY :)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2707559
Thanx Westy;)
0
 

Expert Comment

by:floriangrimm
ID: 2707852
Hi
don't worry about this answer, but it is long time ago I last used Delphi
but

RichEdit can print itself (since D3?)
you can resie richedit and print...

have you the vcl-source? look at it!
(ok, ok a little bit big and sometimes confusing for us little properties clickers....)
0
 

Author Comment

by:westy100697
ID: 2709779
floriangrimm,
             If you read my question at the top I have already stated that I tried this and I also stated why I did not want to use it. Have a read. Thanks anyway.

PS. I aint no property clicker and I certainly aint confused.  What do u mean ??

WESTY :)

0
 

Author Comment

by:westy100697
ID: 2709796
floriangrimm,
             You are talking about the VCL Source file. I see. Well there is not need to look at that as I am trying to print and view using a TImage canvas. This is why Igors answer is so good. Perfect actually as it removes those silly characters from the text when I transfer it to the Canvas.

Anyway this question is now complete so I guess just look out for when I ask another.

WESTY :)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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