Solved

Printing Text Data from a TMemofield ??

Posted on 2000-04-11
14
413 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:westy100697
Comment Utility
I will award you some points however for taking the time.

Cheers,

 WESTY :
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:westy100697
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanx Westy;)
0
 

Expert Comment

by:floriangrimm
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

12 Experts available now in Live!

Get 1:1 Help Now