tags:

views:

1623

answers:

2

I've been searching the reason why the maximum length of String in a TMemo.Lines is 1024, but not found yet.

I have a text file which contains delimited / csv data which length is around 2000 characters. I use a memo to preview it before I process the file.

memo.Lines.LoadFromFile(textFile);

I have set the WordWrap to FALSE, and scrollBar to ssHorizontal. So any record will not be wrapped to the next line.

But when I iterate the memo.Lines, I found that the maximum String hold in each index is 1KB or 1024 characters. The rest is truncated to the next line.

But if I use TStringList to load the file, the row is not truncated to the next index when it reaches more than 1024 characters. This is not happen when I use TRichEdit.

  1. Anyone can explain this phenomena?
  2. Is it the default behavior of TMemo?

I use D2006 to try this.

+1  A: 

There's a TeamB answer on this thread: https://forums.embarcadero.com/thread.jspa?threadID=14035

I'm surprised that TStringList didn't work for you. I'm not quite sure what you mean by

the row is not truncated to the next index when it reaches more than 1024 characters.

I'm assuming the lines are delimited by newlines or CRLFs. Why would it matter if a CSV line exceeded 1024 characters? Please post more details.

TrueWill
I use TMemo to preview the file before I process it. Remember when we try to open a text file using Excel? There is a wizard which preview the content of the file, and guide us how to split the rows etc?I have no issue with TStringList nor with TRichEdit.The problem just occurs when I use TMemo. From the link you and RRUZ mentioned above, TRichEdit also has the similar limitation, but it holds 4096 in max.
WishKnew
That makes sense. One option would be to load it with a TStringList, then display the first n characters in a TMemo (assuming the user just needs to select the delimiter). Another possibility is again load via TStringList, but display the unparsed results in a grid. I don't know if that control has a limitation. You could use a TRichEdit, or search for a custom control that does not have that limitation. Years ago I had a 3rd-party Delphi control that acted like the Excel import wizard, but I don't recall the name.
TrueWill
+1  A: 

WishKnew try this links

https://forums.embarcadero.com/thread.jspa?threadID=14035

http://www.borlandtalk.com/line-length-in-tmemo-vt67596.html

http://groups.google.com/group/borland.public.delphi.vcl.components.using/browse_thread/thread/318fe3240d2860ba

As the great Peter Below says :

...This has nothing to do with the appearend line length limit. This limit is really just visual, caused by the way the control renders its text.

Bye.

RRUZ
-1 for just posting links with no explanation or summary.
Rob Kennedy