Recent

Author Topic: TStringList in Windows10 vs Windows7 work  (Read 9713 times)

noszone

  • New Member
  • *
  • Posts: 33
TStringList in Windows10 vs Windows7 work
« on: December 29, 2021, 11:04:55 am »
My colleague tells that there is difference on how TStringList works depend of OS. On Win10 he said, my TStringList often drops. i.e. just goes to exception and lose it's values. But on Win7 he said, there is no problem. Does anybody can confirm if there is special things in Win10? Or it's a result of his buggy code.

The code is big and I don't have it complete. But he refused TStringList and trying to use now a database selects instead of TStringList for comparing and etc. Thanks.

Some code from project:

Code: Pascal  [Select][+][-]
  1. tsWorkers:=TStringList.Create;
  2.         for a := 0 to form1.ds.DataSet.RecordCount-1 do begin
  3.           for b := 0 to form1.ds.DataSet.Fields.count-1 do begin
  4.             if b = 0 then begin
  5.               at:=form1.ds.DataSet.Fields[b].AsString;
  6.             end else begin
  7.               at:=at+'>'+form1.ds.DataSet.Fields[b].AsString;
  8.             end;
  9.           end;
  10.           tsWorkers.Add(at);
« Last Edit: December 29, 2021, 11:08:31 am by noszone »

Bart

  • Hero Member
  • *****
  • Posts: 4721
    • Bart en Mariska's Webstek
Re: TStringList in Windows10 vs Windows7 work
« Reply #1 on: December 29, 2021, 02:58:26 pm »
I use TStringLists all over the place on my Win10 laptop.
If it crashes, it's my own sloppy coding.

Bart

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TStringList in Windows10 vs Windows7 work
« Reply #2 on: December 29, 2021, 05:39:11 pm »
His buggy code.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10152
  • FPC developer.
Re: TStringList in Windows10 vs Windows7 work
« Reply #3 on: December 29, 2021, 07:24:39 pm »
An issue like that  is not known.

Code relying on the exact sort order could be buggy though, since the default is to use the OS string comparison routine that might be OS dependent.

Still not a bug, but that could trip up buggy code using tstringlist on machines with differing locales.

mas steindorff

  • Hero Member
  • *****
  • Posts: 500
Re: TStringList in Windows10 vs Windows7 work
« Reply #4 on: December 29, 2021, 07:41:07 pm »
the only thing i can think is a RAM limit.  I have found TStringList did have a 2G memory limit before you get a "out of memory" exception in 32 bit mode.  I have not tested the limit in 64bit mode.   
I think either the latest complier has some extra Run time testing to enforce this or windows itself is doing the limit enforcement on the 32bit exe.
something you can check.  Do you get the exception at start or when you get a lot to info in your dataset?
« Last Edit: December 29, 2021, 08:57:08 pm by mas steindorff »
windows 7/10 - laz 2.0 / 1.2.6 general releases

af0815

  • Hero Member
  • *****
  • Posts: 990
Re: TStringList in Windows10 vs Windows7 work
« Reply #5 on: December 29, 2021, 09:37:36 pm »
The code is big and I don't have it complete. But he refused TStringList and trying to use now a database selects instead of TStringList for comparing and etc. Thanks.
To use the select in the DB context is IMHO normaly a better approach.
regards
Andreas

noszone

  • New Member
  • *
  • Posts: 33
Re: TStringList in Windows10 vs Windows7 work
« Reply #6 on: December 30, 2021, 04:23:16 am »
Thank you all for replies.

Do you get the exception at start or when you get a lot to info in your dataset?

I think when there is a data. He uses a TStringList like a stack for string comparison. New data alaways filling this stack, but the size(length) of TStringList is 20-30 rows. New data rewrites old data on stack and like so.

Thaddy

  • Hero Member
  • *****
  • Posts: 11755
Re: TStringList in Windows10 vs Windows7 work
« Reply #7 on: January 09, 2022, 08:38:43 am »
I Also used Tstringlist to mimic a stack in the olden days, but now there are enough stacks available. e.g. in generics.collections, fpc-stl etc.
Example:
Code: Pascal  [Select][+][-]
  1. {$mode delphi}{$H+}
  2. uses generics.collections;
  3. type
  4.   TStringStack = TStack<string>;
  5. // if you prefer {$mode objfpc} then   TStringStack = specialize TStack<string>;  
  6. var
  7.   s:TStringStack;
  8.   p:string;
  9. begin
  10.   s:=Tstringstack.create;
  11.   try
  12.     s.push('test');
  13.     s.Push('test2');
  14.     // etc
  15.     writeln(s.pop)
  16.    finally
  17.      s.free;
  18.    end;
  19. end.
This is also delphi compatible.
See also https://docwiki.embarcadero.com/CodeExamples/Sydney/en/Generics_Collections_TStack_(Delphi)
« Last Edit: January 09, 2022, 10:14:47 am by Thaddy »
Black themes should be banned.

Thaddy

  • Hero Member
  • *****
  • Posts: 11755
Re: TStringList in Windows10 vs Windows7 work
« Reply #8 on: January 09, 2022, 11:24:44 am »
BTW here a lightweight version based on the stack from the contnrs unit:
Code: Pascal  [Select][+][-]
  1. unit stringstack;
  2. {lightweight stringstack ,(c) 2022, Thaddy de Koning. Use as you like}
  3. interface
  4. {$mode objfpc}
  5. uses
  6.   contnrs, sysutils;
  7.  
  8. type
  9.   TStringStackException = class(Exception);
  10.  
  11.   TStringItem = record
  12.     s:string;
  13.   end;
  14.   PStringItem = ^TStringItem;
  15.  
  16.   TStringStack = class(TStack)
  17.   public
  18.     destructor destroy;override;
  19.     procedure Clear;
  20.     Function Count: Integer;
  21.     Function AtLeast(ACount: Integer): Boolean;
  22.     function Push(const AItem: string):string;
  23.     Function Pop: string;
  24.     Function Peek: string;
  25.     Function IsEmpty:Boolean;
  26.   end;  
  27.  
  28. implementation
  29.  
  30.   Destructor TStringStack.Destroy;
  31.   begin
  32.     Clear;
  33.     inherited destroy;
  34.   end;
  35.  
  36.   Procedure TStringStack.Clear;
  37.   begin
  38.     while not IsEmpty do pop;
  39.   end;
  40.  
  41.   Function TStringStack.Count:integer;
  42.   begin
  43.     Result := Inherited Count;    
  44.   end;
  45.    
  46.   Function TStringStack.AtLeast(ACount: Integer): Boolean;
  47.   begin
  48.      Result := Inherited AtLeast(ACount);
  49.   end;
  50.   {$PUSH}{$WARN 5093 OFF since new() initializes}
  51.   function TStringStack.Push(const AItem:String):string;
  52.   var
  53.     r:PStringItem;
  54.   begin
  55.     New(r);    
  56.     r^.s := AItem;
  57.     r := Inherited Push(r);
  58.     Result := r^.s;
  59.   end;
  60.  
  61.   Function TStringStack.Pop:String;
  62.   var
  63.     t:PStringItem;
  64.   begin
  65.     if IsEmpty then
  66.       raise TStringStackException.create('Pop: error: stack is empty');
  67.     t := InHerited pop;
  68.     Result := t^.s;
  69.     Dispose(t);
  70.   end;
  71.    
  72.   Function TStringStack.Peek:String;
  73.   var
  74.     t:PstringItem;
  75.   begin
  76.     if IsEmpty then
  77.       raise TStringStackException.create('Peek: error: stack is empty');
  78.     t := InHerited peek;
  79.     Result := t^.s;
  80.   end;
  81.   {$POP}
  82.   Function TStringStack.IsEmpty:Boolean;
  83.   begin
  84.     Result := Count = 0;
  85.   end;
  86.  
  87. end.
Useful if you do not want to use generics.
It is also faster than Tstringlist as a stack.
« Last Edit: January 12, 2022, 09:55:09 am by Thaddy »
Black themes should be banned.

Thaddy

  • Hero Member
  • *****
  • Posts: 11755
Re: TStringList in Windows10 vs Windows7 work
« Reply #9 on: January 12, 2022, 08:54:59 am »
with hindsight, edited the previous post and added exception handling and simplified the rest a bit.
I added the exception so you can better use it in production code.
Demo:
Code: Pascal  [Select][+][-]
  1. program sstest;
  2. {$mode objfpc}
  3. uses stringstack;
  4.  var
  5.   stack:TStringStack;
  6.  begin
  7. {$if declared(UseHeapTrace)}
  8.   GlobalSkipIfNoLeaks := True; // supported as of debugger version 3.2.0
  9. {$endIf}
  10.   stack := TStringStack.Create;
  11.   try
  12.     try
  13.       { AtLeast}
  14.       writeln('AtLeast 20?: ',stack.AtLeast(20),,' Count is ',stack.count);
  15.       { Push }
  16.       writeln(stack.push('test1'),stack.count:2);
  17.       { Peek }
  18.       writeln('peek: ',stack.peek);
  19.       writeln(stack.push('test2'),stack.count:2);
  20.       writeln('peek: ',stack.peek);
  21.       writeln(stack.push('test3'),stack.count:2);
  22.       writeln('AtLeast 2?: ',stack.AtLeast(2),' Count is ',stack.count);;
  23.       { Pop }
  24.       writeln(stack.pop,stack.count:2);
  25.       writeln('peek: ',stack.peek);
  26.       writeln(stack.pop,stack.count:2);
  27.       writeln('peek: ',stack.peek);
  28.       writeln(stack.pop,stack.count:2);
  29.       writeln('peek: ',stack.peek);
  30.       { this raises exception, as would pop }
  31.       writeln(stack.peek,stack.count:2);
  32.     except
  33.       on E:TStringStackException do
  34.         writeln(E.Message)
  35.       else
  36.         raise;
  37.     end;
  38.   finally
  39.     stack.free;
  40.   end;
  41. end.
« Last Edit: January 12, 2022, 10:01:59 am by Thaddy »
Black themes should be banned.

masy

  • New member
  • *
  • Posts: 7
Re: TStringList in Windows10 vs Windows7 work
« Reply #10 on: January 14, 2022, 05:21:35 am »
To test a Tstringlist I put a visible Listbox(1 and more) on my forms
Listbox(1).items:=a Tstringlist...
Use this always to visualy check the items. If it's works then use:
SL:=TStringlist.create;
  //Youre code
  //BV: INI.ReadSections(listbox1.Items); or INI.ReadSections(SL);
  //BV: INI.ReadSectionsValues(listbox1.Items); or INI.ReadSectionsValues(SL);
SL.Free;

Love Lazarus




Thaddy

  • Hero Member
  • *****
  • Posts: 11755
Re: TStringList in Windows10 vs Windows7 work
« Reply #11 on: January 14, 2022, 06:38:58 am »
That is a bit cumbersome and slow. Besides, he uses the stringlist as a stack, hence I wrote the stringstack (twice: one based on genericks, one bases on Tstack from contnrs)
He is also not a real beginner, or at least his team is not.
Black themes should be banned.

masy

  • New member
  • *
  • Posts: 7
Re: TStringList in Windows10 vs Windows7 work
« Reply #12 on: January 14, 2022, 12:11:13 pm »
I am a control freak...
Like to see my programm issues. If I don't thrust my own code the listboxes stay. On the form (.visible true/false...)

Testing.../Testing...:
boys/girls. So important. Always check for the in/mpossible:
Dividing thru a zero value or not reqocnized value: Lazarus goes complete 'CRAZY!!!'...

Working with TStringlists is a fine/beautiful option. Use it as much as possible. 
The TListbox is in performing/testing a much better/slower choise. YSWYG: You See What You Get.
You 'throw' a listbox on the form and got the totaly visible control of Youre own programm...
You can replace/delete the listboxes at wish/everytime.
But in testing listboxes are 'pearls'.

What if Lazarus crashes everytime. You try to divide a string/value by zero. Got this?
Just one value in Youre stringlist with hunderds/thousands of values. And just that one...
That one item crashes Youre programm totally...

Don't let this happen to You. Check visualy with listboxes. Don't listen to the experts.
Be a complete Newbie. Within programming the i/n/mpossible is possible!!!

Hey Thaddy,

I see on Youre icons that You are mad at me?

Thaddy:
I am 64 Years old.
My doughter = 41 years. That are the years that I am programming (Delphi,PHP, Basic, Html).
Thaddy, are You that old? 41 years?

Don't be mad on a person that You dont'know'.
I hate the red blinking devils on this site.

Do something about that Thaddy. Love You ;-))...

And let me go:
More then 40 years of experiance in a flow...


Greetings,

Marcel/Masy...
























-+

« Last Edit: January 14, 2022, 01:10:02 pm by masy »

Thaddy

  • Hero Member
  • *****
  • Posts: 11755
Re: TStringList in Windows10 vs Windows7 work
« Reply #13 on: January 14, 2022, 12:23:44 pm »
I am a control freak...
Like to see my programm issues. If I don't thrust my own code the listboxes stay. On the form (.visible true/false...)
Me too, that's why I use the debugger for that.... >:D >:D >:D
« Last Edit: January 14, 2022, 01:22:04 pm by Thaddy »
Black themes should be banned.

dbannon

  • Hero Member
  • *****
  • Posts: 2045
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TStringList in Windows10 vs Windows7 work
« Reply #14 on: January 14, 2022, 12:31:15 pm »
Wow, I would find that sort of debugging, with listboxs cluttering my app's gui, very, very tedious.

In linux, all I need do is put a line like "writeln(SL.text)" in there when I need to see what really is in there. I usually put a line above it indicating which method generated that particular dump, helps in tracking how the content changes and helps in finding it to remove when no longer needed. And have a console window there in the background.

A little harder in Windows of course, debugln() and directing to a file ...

One day, we may be able to see a stringlist's content in the watches window, now, that might be cool but could also be messy  ;-)

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

 

TinyPortal © 2005-2018