Solved

Chasing a quick answer for TMemo ??

Posted on 2000-04-04
14
224 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
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 300 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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