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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

Printing Text Data from a TMemofield ??

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
westy100697
Asked:
westy100697
  • 9
  • 2
  • 2
  • +1
1 Solution
 
westy100697Author Commented:
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
 
rwilson032697Commented:
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
 
westy100697Author Commented:
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
Technology Partners: 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!

 
westy100697Author Commented:
I will award you some points however for taking the time.

Cheers,

 WESTY :
0
 
rwilson032697Commented:
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
 
westy100697Author Commented:
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
 
ITugayCommented:
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
 
westy100697Author Commented:
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
 
westy100697Author Commented:
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
 
westy100697Author Commented:
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
 
ITugayCommented:
Thanx Westy;)
0
 
floriangrimmCommented:
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
 
westy100697Author Commented:
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
 
westy100697Author Commented:
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!

  • 9
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now