Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Chasing a quick answer for TMemo ??

Posted on 2000-04-04
14
Medium Priority
?
233 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
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: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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