Solved

Printing Text Data from a TMemofield ??

Posted on 2000-04-11
14
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

623 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