Home > front end >  How to save multiple lines (strings) from a rich edit into an array of string?
How to save multiple lines (strings) from a rich edit into an array of string?

Time:09-25

I don't know if it works or not, because I can't use "trace into". When I try to display the array values back in the TRichEdit using a for loop after clearing it, nothing gets displayed, it just turns blank.

procedure TfrmEncryption.sedOffsetClick(Sender: TObject);
var
  K : integer;
begin
  for K := 1 to 26 do
  begin
    arrOffset[K] := redOutOffset.Lines.Strings[K];
  end;

  redOutOffset.Clear;

  for K := 1 to 26 do
  begin
    redOutOffset.Lines.Strings[K] := arrOffset[K];
  end;
end;

CodePudding user response:

I don't know if it works or not, because I can't use "trace into".

Make sure you have "Use debug dcus" enabled in the Project Options. Then you should be able to step into the VCL's source code with the debugger at runtime.

When I try to display the array values back in the TRichEdit using a for loop after clearing it, nothing gets displayed, it just turns blank.

After you Clear() the RichEdit, you can't index into its Strings[] anymore, since there is no more data. You will have to use Lines.Add() instead of Lines.Strings[K], eg:

redOutOffset.Lines.BeginUpdate;
try
  redOutOffset.Clear;

  for K := 1 to 26 do
  begin
    redOutOffset.Lines.Add(arrOffset[K]);
  end;
finally
  redOutOffset.Lines.EndUpdate;
end;
  • Related