Jump to content

memo lines ?

Recommended Posts

Hmmm, I am missing something.


Lines does not exist for memo (TW3Memo)

Syntax Error: There is no accessible member with name "lines" [line: 46, column: 23, file: Form1]


procedure TForm1.InitializeForm;
var item : string;
  // this is a good place to initialize components


  for item in w3memo1.lines do


Link to post
Share on other sites
  • Administrators
16 hours ago, Czar said:

I believe it is a good example where Smart Pascal should mirror Delphi

Well, introducing Lines as a property is not hard if we do it by splitting the memo text. However, when you'd loop through it, it'd be horribly inefficient as every access to Lines (count or accessing any line), would trigger the split from original text.

Link to post
Share on other sites
  • Moderators

interesting. Basically you would need to keep Text(string) and Lines(array of string) in sync at all times, and only sync when data changes in either one of them

I suppose you could define a Lines array, and override the js push method (for this array only)

Lines = []
Lines.push = function(data) {
  ... update Memo.text with data ....

  return Array.prototype.push.call(this, data);

and in this override update Memo.Text (or re-create Text from Lines). That would cover the use case of Memo1.Lines.Add(data) and I suppose similarly for deletes.

The other way around (changing Text instead of Lines) you would need to extend the SetText setter to update Lines (and not get into an infinite loop) 

Looking forward to see your solution :)



Link to post
Share on other sites
  • Administrators
7 hours ago, Czar said:

Sorry both the previous posts go over my head. I am a humble user and abuser of Smart Mobile Studio. 

Ok, lets elaborate. This is pretty universal regardless of programming languages.

Suppose I just add:

property Lines: TStrArray read GetLines;

...and GetLines does take the current text and splits it into an array.

Then you have code like this:

for var i:=0 to Memo.Lines.Count-1 do

When the code is run, every time Memo.Lines is accessed, it results in a call to GetLines. So, if you have 1000 lines, the code above would result in 1001 calls to GetLines and 1001 splits of the whole text to an array. This is what my message meant.

What @lynkfswrote is about a more advanced solution where the memo would store the contents as both text (as it does now) and a separate Lines-array. That would eliminate the performance problem, but it'd introduce other problems like:

  • More memory usage as data is stored internally twice.
  • All the challenges to make sure that both the text and the array match, no matter how the memo contents are changed.

I haven't tested if @lynkfs solution works and what it requires.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...