tstringlist

Using TStringList's AddObject with integers?

有些话、适合烂在心里 提交于 2019-12-03 11:19:06
Using delphi 7: How can I add an integer to the object portion of a stringlist item, using AddObject ? How can I retrieve the integer back from a object property of stringlist item? How do I free all objects and list when done? Q: How can i add an integer to the object portion of a stringlist item, using AddObject? A: Just cast the integer value to TObject List.AddObject('A string',TObject(1)); Q: How can a retrieve the integer back from a object property of stringlist item? A: Cast to integer the Object Value AValue := Integer(List.Objects[i]); Q: How do i free all objects and list when done?

Why variables are declared as TStrings and created as TStringList?

試著忘記壹切 提交于 2019-12-03 10:22:23
Why variables are declared as TStrings and created as TStringList ? eg: the var sl is declared as TStrings but created as TStringList var sl : TStrings; begin sl := TStringList.Create; // add string values... sl.Add( 'Delphi' ); sl.Add( '2.01' ); // get string value using its index // sl.Strings( 0 ) will return // 'Delphi' MessageDlg( sl.Strings[ 0 ], mtInformation, [mbOk], 0 ); sl.Free; end; To my mind that is rather pointless albeit completely harmless. You could perfectly well declare sl to be TStringList and I would always do it that way. For a reader of the code it makes the list of

How can I search faster for name/value pairs in a Delphi TStringList?

余生颓废 提交于 2019-12-03 01:35:23
I implemented language translation in an application by putting all strings at runtime in a TStringList with: procedure PopulateStringList; begin EnglishStringList.Append('CAN_T_FIND_FILE=It is not possible to find the file'); EnglishStringList.Append('DUMMY=Just a dummy record'); // total of 2000 record appended in the same way EnglishStringList.Sorted := True; // Updated comment: this is USELESS! end; Then I get the translation using: function GetTranslation(ResStr:String):String; var iIndex : Integer; begin iIndex := -1; iIndex := EnglishStringList.IndexOfName(ResStr); if iIndex >= 0 then

TStringList vs. TList<string>

▼魔方 西西 提交于 2019-12-03 01:10:29
what is the difference in using a standard type sl: TStringList compared to using a generic TList type sl: TList<string> ? As far as I can see, both behave exactly the same. Is it just another way of doing the same thing? Are there situations where one would be better than the other? Thanks! TStringList is a descendant of TStrings. TStringList knows how to sort itself alphabetically. TStringList has an Objects property. TStringList doesn't make your code incompatible with all previous versions of Delphi. TStringList can be used as a published property. (A bug prevents generic classes from

TStringList.LoadFromFile - Exceptions with Large Text Files

╄→尐↘猪︶ㄣ 提交于 2019-12-01 22:20:55
问题 I'm running Delphi RAD Studio XE2. I have some very large files, each containing a large number of lines. The lines themselves are small - just 3 tab separated doubles. I want to load a file into a TStringList using TStringList.LoadFromFile but this raises an exception with large files. For files of 2 million lines (approximately 1GB) I get the EIntOverflow exception. For larger files (20 million lines and approximately 10GB, for example) I get the ERangeCheck exception. I have 32GB of RAM to

Delphi: StringList Delimiter is always a space character even if Delimiter is set

无人久伴 提交于 2019-11-27 20:58:16
I am having trouble with the delimiter in the TStringList Class. Take a look: var s: string; sl: TStringList; begin sl := TStringList.Create; s := 'Users^foo bar^bar foo^foobar^barfoo'; sl.Delimiter := '^'; sl.DelimitedText := s; ShowMessage(sl[1]); end; sl[1] SHOULD return 'foo bar' sl[1] DOES return 'foo' It seems that the delimiter is now '^' AND ' ' Any ideas? Roee Adler You should set s1.StrictDelimiter := True for spaces not to be considered delimiters, more info here . Since you work in a version that does not support the above (as was clarified after the answer was submitted), you have

How can I get TStringList to sort differently in Delphi

青春壹個敷衍的年華 提交于 2019-11-27 13:09:37
问题 I have a simple TStringList. I do a TStringList.Sort on it. Then I notice that the underscore "_" sorts before the capital letter "A". This was in contrast to a third party package that was sorting the same text and sorted _ after A. According to the ANSI character set, A-Z are characters 65 - 90 and _ is 95. So it looks like the 3rd party package is using that order and TStringList.Sort isn't. I drilled down into guts of TStringList.Sort and it is sorting using AnsiCompareStr (Case Sensitive