Recent

Author Topic: [SOLVED] Maximum number of rows in TMemo component?  (Read 2390 times)

Jiří Huňáček

  • New Member
  • *
  • Posts: 29
[SOLVED] Maximum number of rows in TMemo component?
« on: February 28, 2023, 06:12:21 pm »
Hello to everybody,

I need help with the TMemo component. I am creating an import from a CSV file and the output should be a SQL BLOCK statement with INSERTs, which I want to insert into the MEMO component.

Code: Pascal  [Select][+][-]
  1. EXECUTE BLOCK AS BEGIN
  2.     INSERT INTO <table> (<columns>) VALUES (<values>)
  3.     INSERT ...
  4.     INSERT ...
  5.     ...
  6. END;

I have two forms created. Form1 contains, among other things, the showSQL button, which is used to launch Form2 with the ShowModal command. There is only a MEMO component on Form2.

For the test, I created a CSV file with 20000 lines. Creating a Stringlist and assigning it to the Form2.MEMO component will be ok. I then run Form2.ShowModal. On first run, Form2 opens fine and there are 20000 rows in MEMO. But when I close Form2 and want to open it again, the program displays an error

"Failed to create win32 control error 0: operation completed successfully."

If the number of source rows is at most 5126, the error will not appear and I can display the second form as many times as I want.

I am attaching a short project with two forms, in which I insert only the text "Number "+<integer variable> into MEMO.

I don't know if I'm making a mistake somewhere or if MEMO is somehow limited by the number of lines.

I use Lazarus version 2.0.10, FPC version 3.2.0, SVN Revision 63526 - on Windows 10
« Last Edit: April 15, 2023, 04:59:12 pm by Jiří Huňáček »
Best regards / mit freundlichen Grüßen / s pozdravem
Jiří Huňáček (George)

Lazarus v3.6 and FPC v3.2.2 on Windows 10 x64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Maximum number of rows in TMemo component?
« Reply #1 on: February 28, 2023, 06:20:47 pm »
Slightly modified your source, havent tried original tbh
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   xNumber: integer;
  4.   xStringList: TStringList;
  5. begin
  6.   xStringList:=TStringList.Create;
  7.   try
  8.     for xNumber:=1 to 20000 do // number of rows before crash = 5126
  9.       xStringList.Add('Number '+inttostr(xNumber));
  10.     Form2.Memo1.Lines.BeginUpdate;
  11.     Form2.Memo1.Lines.Clear;
  12.     Form2.Memo1.Lines.Assign(xStringList);
  13.     Form2.Memo1.Lines.EndUpdate;
  14.   finally
  15.     xStringList.Free;
  16.   end;
  17.   Form2.ShowModal;
  18. end;
Lazarus 2.3.0 (rev main-2_3-2889-g1b9d3d4cbf) FPC 3.2.2 x86_64-win64-win32/win64
Works without any problems here on Windows 64bit.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Thaddy

  • Hero Member
  • *****
  • Posts: 16782
  • Ceterum censeo Trump esse delendam
Re: Maximum number of rows in TMemo component?
« Reply #2 on: February 28, 2023, 06:22:05 pm »
Under Windows the limit is 32767 lines unless you define BOTTOMLESS. I do not know the Lazarus internals, but that should be possible with Lazarus too - on windows -, otherwise it is a bug.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Ten_Mile_Hike

  • Full Member
  • ***
  • Posts: 100
Re: Maximum number of rows in TMemo component?
« Reply #3 on: March 07, 2023, 09:59:47 pm »
Your reply is correct... however I'm going to experiment "just for the heck of it" to compare the time required for 5000 line
Tmemos and Tstringlists  to see how much (if any) difference it actually makes
 
   Memo1.Lines.BeginUpdate;
   Memo1.Lines.Clear;
   Memo1.Lines.Assign(xStringList);
   Memo1.Lines.EndUpdate;

      ***Versus***

 Memo1.text:=xStringlist.text
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

jamie

  • Hero Member
  • *****
  • Posts: 6873
Re: Maximum number of rows in TMemo component?
« Reply #4 on: March 07, 2023, 11:09:49 pm »
what isn't being told here and it's no surprise, the memo in windows is 65k bytes of storage.

It has nothing to do with line counts.

one line could occupy the complete bundle of memory thus making it only one line.

if you put in empty lines you get the Line ending characters which are two of course and this would lead to 32k lines.

 Buit you are not going to get that if you have actual content in it.

 it's not about the line count but about the total mass of the strings with line endings.

 You can enlarge the memo, that is true, however, the memo is exactly what it is, just a memo and not a story book.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 16782
  • Ceterum censeo Trump esse delendam
Re: Maximum number of rows in TMemo component?
« Reply #5 on: March 08, 2023, 07:51:47 am »
what isn't being told here and it's no surprise, the memo in windows is 65k bytes of storage.
No it is 32 k because it is signed. On Windows you can also set the Bottemless parameter, which means the content can be much longer. Bottomless is a Windows control property, not a Pascal property. See MSDN.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Josh

  • Hero Member
  • *****
  • Posts: 1371
Re: Maximum number of rows in TMemo component?
« Reply #6 on: March 08, 2023, 07:57:14 am »
HI

Attached project, create 96K lines which takes up 4+MB of memory, and loads in memo.

Laz & FPC Fixes Win64.



The best way to get accurate information on the forum is to post something wrong and wait for corrections.

WooBean

  • Sr. Member
  • ****
  • Posts: 282
Re: Maximum number of rows in TMemo component?
« Reply #7 on: March 08, 2023, 09:16:12 am »
what isn't being told here and it's no surprise, the memo in windows is 65k bytes of storage.
No it is 32 k because it is signed. On Windows you can also set the Bottemless parameter, which means the content can be much longer. Bottomless is a Windows control property, not a Pascal property. See MSDN.

Well, as Lines in TMemo are TStrings and their property Count is defined as "Count: Integer read GetCount", and the system unit defines Integer as a signed 16-bit integer and .... when DELPHI or OBJFPC  mode are active, then the objpas unit redefines Integer  as a 32-bit integer.

So the simple answer for TS is that Lines.Count limit in TMemo is 2^31-1=2147483647.
 
Period.
« Last Edit: March 08, 2023, 09:25:04 am by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

PascalDragon

  • Hero Member
  • *****
  • Posts: 5936
  • Compiler Developer
Re: Maximum number of rows in TMemo component?
« Reply #8 on: March 08, 2023, 11:00:06 pm »
So the simple answer for TS is that Lines.Count limit in TMemo is 2^31-1=2147483647.
 
Period.

That's the limit of the Pascal side of things, however the operating system / widgetset might have different limits and in the end those will win out.

Jiří Huňáček

  • New Member
  • *
  • Posts: 29
Re: [SOLVED] Maximum number of rows in TMemo component?
« Reply #9 on: April 15, 2023, 05:00:16 pm »
Hello everybody,

solved by installing the latest version of Lazarus.
Best regards / mit freundlichen Grüßen / s pozdravem
Jiří Huňáček (George)

Lazarus v3.6 and FPC v3.2.2 on Windows 10 x64

 

TinyPortal © 2005-2018