?
Solved

Chasing a quick answer for TMemo ??

Posted on 2000-04-04
14
Medium Priority
?
231 Views
Last Modified: 2010-04-04
Hi,
   Just a quick question about TMemo components and how I can align text in the memo. Right I will start at the beginning....

If I have a long line of text that I want to add to a TMemo and I have word wrap on, how can I format the memo so that the second line is indented a set amount of characters. Okay that sounds easy doesn't it. But there is more. If I have for example the following set of characters at the start of the line with no preceding spaces and 2 spaces after the 1000

eg  500 - 1000+'  '+'The text starts here'
                   
The second line of text needs to start underneath 'The on the first line. I have tried using #161 for the length of the initial string but it ends up being about 5 characters short. There is obviously some width difference between a space and a normal character so what is the answer ??
I have also tried adding to the second line a string such as '          ' to whatever the length of 500 - 1000+2spaces is, but it always is too short. Anyone have a clue on this one??


Need a quick answer so will offer some good points.

Regards,

 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
14 Comments
 

Expert Comment

by:Gurkan
ID: 2686402
Hi,
If it is not a big problem, you can use a fixed size font, and try again.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2686546
You may try use TRichEdit instead TMemo, it has more possibilities for text formatting.
-----
Igor
0
 
LVL 9

Accepted Solution

by:
ITugay earned 1200 total points
ID: 2686607
This is working sample you can try. Sample show text formatting you need.


procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
   with Richedit1 do
   begin
      Lines.Clear;
      Paragraph.TabCount:=2; // number of tabs positions
      Paragraph.Tab[0]:=70;    // first position (in pixels)
      Paragraph.Tab[1]:=200;  // second position
      Lines.Add('0-500'+#9+'first string'+#9+'1');
      Lines.Add(#9+'comment for first string');
      Lines.Add('1000-2000'+#9+'second string'+#9+'2');
      Lines.Add(#9+'comment for second string');
   end;
end;

------
Cheers,
Igor.
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!

 

Author Comment

by:westy100697
ID: 2686740
Will try this idea and see how it goes.

WESTY :|
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2686742
Listening
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2686758
Maybe you could use tabs instead of space
and set the wanttabs property to true...
add the car #9 instead to your text...
0
 

Author Comment

by:westy100697
ID: 2687906
The ideas here are fine so far except for one thing. I need the place where the first tab is put to be more dynamic as the first part of the line will not always be the same width. The best way I can think of doing this is to find the width of the text in pixels rather than characters. Anyone know of a function to do this ? I will also keep looking. ITugay said some good stuff there but just hard coding the Tabs is not what I need. I need to make it determinable based on the width of that first piece of text plus 2 spaces. This means it could be '0 - 50' or '1500 - 10000'. As you can see the widths of these 2 are different and just finding the string length of these and formatting the next lines start with that many blanks will not work. Pixel widths will but how do I get them other than using OnMouseMove which is definitely not ideal.

WESTY :)
0
 

Author Comment

by:westy100697
ID: 2687914
Also it doesn't really matter if I use a RichEdit or Memo as either will work fine for this project I am working on. Need ideas though ASAP on how to format that text.

Cheers,

 WESTY :)
0
 

Author Comment

by:westy100697
ID: 2687923
Canvas.Textwidth is the sort of routine I am after except it needs to be for a String or PChar.

WESTY :)
0
 

Author Comment

by:westy100697
ID: 2687989
Okay I have come up with a way to get the Pixel Width but does anyone have a better suggestion. Currently I just added the text to a Hidden Comboboxes' canvas and used the TextWidth property to get the width in pixels based on current font size and type. This works okay but is there a better way ??

By the way I am using a RichEdit or Memo so the data entered can be saved to a Memofield in a database table.

WESTY :)
0
 

Author Comment

by:westy100697
ID: 2688145
Okay I have solved it. I used a hidded TImage and then used TextOut based on the RichEdit Font Size. This gives me the Pixel width of the text and then I set Tab[0] to that width. Works Well.
Thanks people. Will award ITugay the points later today unless someone can come up with a better solution. The TRichEdit is definitely better than TMemo with more options for formatting.
Well I will check this again this evening and if no-one has got a better solution ITugay gets the points.

PS.(It is currently 9:00am here so plenty of time to see if anyone can better the solution)

Thanks,

 WESTY :)
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2688563
listening
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2689155
Hi westy,

I don't know what you consider a better solution, but for the text size determination I'd recommend this way:

var
  DC: HDC;
  S: String;
  SIze: TSize;

begin
  DC := GetDC(RichEdit1.Handle);
  S := TextToGetWidthFor;
  GetTextExtentPoint32(DC, PChar(S), Length(S), Size);
  RichEdit.Paragraph.Tab[0]:= Size.cx;
  ReleaseDC(RichEdit1.Handle, DC);
end;

Ciao, Mike
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2689393
Look at TStringGrid too. It may be good solution to show text in cells.
----
Igor.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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