I work with memo.

Three tasks memo1 step by step: first, the memo1 loaded into memo1 , then the lines from memo1 mixed, then you need to output them to the same memo , replacing the text that was. The replacement of lines of the following type was also considered:

  Text : string; begin Memo.Lines.Text := 'Замена текста в Memo'; Text := StringReplace(Memo.Lines.Text, 'Memo', 'компоненте Memo', [rfReplaceAll, rfIgnoreCase]); Memo.Lines.Text := Text; 

But I have a dynamic array of strings in memo. I use three memo all works, but it is rather non-compact, I would like to do everything in one memo.

Tell me, please, how to do it.

here is a part of the code, the text file is loaded up to a certain line, the number of this line is set by the user in edit. With memo was so

 var i,k:integer; sl: tstringlist; begin k:= StrToInt(Edit2.Text); sl:=tstringlist.create; sl.loadfromfile('Text.txt'); for i := 0 to k - 1 do Memo1.Lines.Add(sl[i]); sl.Free; 

I try with tstringlist ..
var sl: tstringlist; // array for further work with it sl1: tstringlist; // array to load the file i, k: integer; begin kurs: = StrToInt (Edit1.Text);

  if ((kurs=1) and (ComboBox1.ItemIndex=0)) then k:= StrToInt(Edit2.Text); sl1:=tstringlist.create; sl1.loadfromfile('MyFile.txt'); for i := 0 to k - 1 do sl.Add(sl1[i]);//так же sl.Add(sl1.Strings[used[i]]); тоже возникает ошибка( sl.Free; 
  • you call sl.Free ;, and then you call sl.Add, here you have an error, the call to the destroyed object. - AlexAndR

1 answer 1

The easiest thing for you is to use one memo and two instances of TStringList . Then, roughly speaking, Memo2.Lines will be enough to replace with StringList1 , and Memo3.Lines with StringList2 . Memo, which is used to display, will not touch.

  • that is, the stringlist will not be displayed and will be used only for working with its elements? and is it difficult to replace the output of arrays from memo to stringglist? just the work is almost finished - Smile
  • Yes, the fact is that in Delphi there is a visual class TMemo, which is displayed, inside it there is a field Lines, in which data is stored. This class is absolutely compatible with TStringList, so almost nothing will have to be redone, if there are difficulties - send a code fragment with three Memo, I will correct for the version with StringList. It’s just harder to explain things in words. - AlexAndR
  • I added a code in my message .. that I tried - Smile