Recent

Author Topic: (Solved)Memo  (Read 1606 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
(Solved)Memo
« on: October 31, 2020, 05:58:09 am »
(Solbed) I think. I Move the text file into a listbox and then display on a memo. Seems to work.

I checked the Array and the indents were in the array. Just lost it moving from array to Memo for some reason.

I'm reading a text file into a listbox then loading it into an array and displaying the lines of the array in a MEMO.

The text file has formatting which would look like this:

  function Tform1.ThisIsAProcedure(S   : String; S1 : String; S2 : String;
                                                    S3 : String; S4 : String ) : String;

When it displays in the memo it looks like this:


function Tform1.ThisIsAProcedure(S   : String; S1 : String; S2 : String;
 S3 : String; S4 : String ) : String;

I loose the indentation.

Is there something I'm doing wrong or some way around this?

Thanks


  .
« Last Edit: November 02, 2020, 08:35:54 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: (Solved(Memo)
« Reply #1 on: October 31, 2020, 09:02:16 am »
The memo's WordWrap property controls this effect.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: (Solved(Memo)
« Reply #2 on: October 31, 2020, 11:58:24 am »
The memo's WordWrap property controls this effect.

I don't think that's the problem; after all, two lines are two lines and WordWrap shouldn't mess with that.

To the OP, are you using a monospaced font in the memo? If not that might be it, though there should still be some indentation even with proportional fonts.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: (Solved(Memo)
« Reply #3 on: October 31, 2020, 05:09:50 pm »
if memory serves, using READLN I believe to read text files may trunk the spaces to the left.

so that would mean the Listbox does not have the spaces in it.

I suppose something else could be happening too but I would need to see more code  ;D
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: (Solved(Memo)
« Reply #4 on: October 31, 2020, 06:13:05 pm »
@Jamie

Using AFileStream to load the listbox.

@howardpc

Have tried with Wordwrap on/off

Couldn't see any difference.

@lucamar
 Don't know if I'm using a proportional font or not. Using Calibra.

I now go from the listbox to the memo and it works fine. Have dumped the array load.

Thanks All.



FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: (Solved(Memo)
« Reply #5 on: October 31, 2020, 08:35:10 pm »
An alternative, if you're doing that to avoid reading the file twice, would be to load it to a TStringList; from there you can easily load it to any other TStrings descendant or alike, like TListBox.Items or TMemo.Lines.

But then, TListbox.Items acts (very) basically as a StringList, so I suspect the problem might have come in when you transferred to the array. It would be nice to know what you were doing, if just to get a clearer view of the problem ...   
« Last Edit: October 31, 2020, 08:39:52 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: (Solved(Memo)
« Reply #6 on: October 31, 2020, 08:53:19 pm »
@lucimar

your up late.

I agree. I think the way to go is to load the test file somehow into a TStringList then I could do the following:  Memo1 := TStringList.

I'm going to try that in a demo program. Not very knowledgeable with TStringList's.

Would that work?
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: (Solved(Memo)
« Reply #7 on: November 01, 2020, 01:23:23 pm »
TStringList is the basic implementation of the TStrings class, which is also the base class for most of the "multi-line text" storage properties such as TListBox.Items, TMemo.Lines, etc.

What you would do, for example, would be something like:

Code: Pascal  [Select][+][-]
  1.   { Load the text }
  2.   TheText := TStringList.Create;
  3.   TheText.LoadFromFile('somefile.txt');
  4.   { Copy it to a memo and a listbox }
  5.   Memo.Lines.AddStrings(TheText, True);
  6.   ListBox.Items.AddStrings(TheText, True);

As you can see, it's basically a question of copying TStrings to TStrings, which could probably be done also as:
Code: Pascal  [Select][+][-]
  1.   Memo.Lines.Assign(TheText);
  2.   ListBox.Items.Assign(TheText);
but I've had some surprises with Assign in the past, so I tend to avoid it unless I know what exactly it is doing and since, in this case, we have that nice AddStrings()  ...  :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: (Solved(Memo)
« Reply #8 on: November 01, 2020, 02:19:52 pm »
Best way of copying a TStrings content to another one is using Text or Commatext property.

    AMemo.Strings.Text := AStringList.Text;

because TStrings descendants could be slightly different from each other, and I experienced Assign etc. not working properly a few times.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: (Solved(Memo)
« Reply #9 on: November 01, 2020, 03:57:14 pm »
Best way of copying a TStrings content to another one is using Text or Commatext property.

Yes, that's another, and very valid, option though sometimes it's (sligthly) slower than AddStrings().

Quote
because TStrings descendants could be slightly different from each other, and I experienced Assign etc. not working properly a few times.

Assign() is somewhat "special", because we are dealing here with at least one and potentially many managed types and it's not always obvious what it's doing with them. The base TStringList class, though, is a rather straight-forward implementation of TStrings and it has less "gotchas" and surprises than other descendants (like, say, the inconsistent behaviour of TMemo.Lines on different platforms).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: (Solved(Memo)
« Reply #10 on: November 01, 2020, 05:54:08 pm »
@lucamar

I like that. It would replace a lot of code loading a listbox down to 4 lines of code. I wouldn't really have to load the listbox. The program has a debug option and when true it will load the listbox so you can see what is loaded compared to what is displayed in the memo. 

I going to try and implement that in a few days.

Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018