Solved

Chasing a quick answer for TMemo ??

Posted on 2000-04-04
14
221 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
14 Comments
 

Expert Comment

by:Gurkan
Comment Utility
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
Comment Utility
You may try use TRichEdit instead TMemo, it has more possibilities for text formatting.
-----
Igor
0
 
LVL 9

Accepted Solution

by:
ITugay earned 300 total points
Comment Utility
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
 

Author Comment

by:westy100697
Comment Utility
Will try this idea and see how it goes.

WESTY :|
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Listening
0
 
LVL 4

Expert Comment

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

 

Author Comment

by:westy100697
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
listening
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
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
Comment Utility
Look at TStringGrid too. It may be good solution to show text in cells.
----
Igor.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

10 Experts available now in Live!

Get 1:1 Help Now