Board index » delphi » TStringList can save strings, but integers?
johannes_ba...@gmx.TUDASWEG.de (Joe)
Delphi Developer |
Mon, 02 Jul 2001 03:00:00 GMT
|
johannes_ba...@gmx.TUDASWEG.de (Joe)
Delphi Developer |
Mon, 02 Jul 2001 03:00:00 GMT
TStringList can save strings, but integers?
Hi Guys,
I know you can save strings dynamically by simply doing the following: Var X : TStringList; But how can I save Integer-Values in such a data-array not by doing Bye Joe ====================================================== |
Owen Heber
Delphi Developer |
Mon, 02 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?You should still be able to use a TStringList to store an integer value withut converting it. Look up the AddObject method. (Or am I thinking about a TList object?). Anyway, the object can be any object, a tstring, aTQuery, etc. QuoteJoe wrote: |
Peter N Rot
Delphi Developer |
Mon, 02 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?QuoteSimon Reye wrote in message <369E8D38.39DC3...@aecorp.com.au>... -- |
Simon Rey
Delphi Developer |
Tue, 03 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?Joe, You could use a TList and muck around with pointers to integers (TList If only Delphi had dynamic arrays like C/C++ huh. Does Delphi 4 have dynamic arrays (a rumour I heard)? Simon QuoteJoe wrote: |
AlanGLLo
Delphi Developer |
Tue, 03 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?In article <369e5642.934...@news.odn.de>, johannes_ba...@gmx.TUDASWEG.de (Joe) Quote>Var X : TStringList; or x.InsertObject(0, 'A', pointer(12345); . . and get them with MyInt := integer(x.Objects[0]); // type-cast back again Having already stored a string you could then :- x.Objects[1] := pointer(12345); // but the string _must_ have been added first. A pointer is a DWord and so is an integer, so object storage can hold integers, Alan Lloyd |
VBDi
Delphi Developer |
Wed, 04 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?Im Artikel <369E8D38.39DC3...@aecorp.com.au>, Simon Reye <s.r...@aecorp.com.au> Quote>Does Delphi 4 have dynamic arrays (a rumour I heard)? But I don't know the cost, in bytes, so a TList will be a good solution anyhow. DoDi |
VBDi
Delphi Developer |
Thu, 05 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?Im Artikel <369E8F6A.D0A27...@wt.net>, Owen Hebert <ow...@wt.net> schreibt: Quote>Anyway, the object can be any object, a tstring, aTQuery, Objects array, or in a dynamic array. But I have problems with the compiler, that rejects e.g. "with dynamic_array[i] do", at least if the array contains references/pointers to records. How should references to records be put into a dynamic or Objects array? Example: DoDi |
AlanGLLo
Delphi Developer |
Thu, 05 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?In article <19990117011520.17758.00004...@ngol08.aol.com>, vb...@aol.com Quote(VBDis) writes: store them to file. Alan Lloyd |
Markku Nevalaine
Delphi Developer |
Thu, 05 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?QuoteVBDis wrote: problem you describe. It uses TList to keep hold of a bunch of dynamic records. type var ... You can also pass those dynamic records as a function parameter: function TOrderForm.MakeInvoice(Var List:TList) Markku Nevalainen |
Sundial Service
Delphi Developer |
Thu, 05 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?QuoteVBDis wrote: storage (not a class, which is a pointer). So "x" consists of physical chunks. The dynamic-array implementation "appears to be just like a Pascal array" although its implementation is obviously different under-the-covers. But let me generalize a little to the question brought-up by the title Any container-class implements "read" and/or "write" methods, possibly The "Component Writer's Guide" is a very thin book that is easy to /mr/ |
John
Delphi Developer |
Thu, 05 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?You can store integers in a Tlist or a TStringlist by casting them as pointers mystringlist.addobject('string',pointer(integer value)); or in a tlist mylist.add(pointer(integer value)); remember to cast them back when reading them integer(mylist.items[index]) John |
VBDi
Delphi Developer |
Sat, 07 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?Im Artikel <36A219C3.3...@sundialservices.com>, Sundial Services Quote>The dynamic-array implementation "appears to be just like a interesting question: a dynamic array really allocates the memory for every member. Remaining questions about dynamic arrays: Or, in a wider scope: - What's the effect of 'var' on subroutine arguments of some class? Another - Are 'const' arguments also 'var', i.e. pointers? Thank you all for your assistance :-) |
Cameron McCormac
Delphi Developer |
Sat, 07 Jul 2001 03:00:00 GMT
Re:TStringList can save strings, but integers?Quote>- do assignments to members result in a physical copy? internally, dynamic arrays are considered as ^array (as you may have seen in the CodeInsight windows). Classes derived from TPersistent, when you assign them to another, e.g. MyObject1 := MyObject2 will make MyObject1 refer to MyObject2's data (i.e., it just assigns the pointer MyObject2 has to MyObject1). However, if you do MyObject1.Assign(MyObject2), it will copy the data. Quote>- do arrays of some class contain references to the instances? data. Quote>Or, in a wider scope: all, they just contain the data. Thus, when you pass a record to a procedure, the whole record will get put on the stack (I think). If it's a var paremeter, though, it will pass the address this data is stored at, effectively passing @TheRecord. When you pass an object, the pointer is always passed. Quote>- What's the effect of 'var' on subroutine arguments of some class? Another you are passing a variable. It's passed as a pointer to the object no matter what. Quote>- Are 'const' arguments also 'var', i.e. pointers? object. If it's just a simple type or a record, it's passed by value (just as it would if the const wasn't there). However, if it's an object, the pointer to the object is actually passed. The const in this case protects you from assigning a different pointer to that variable. You can still alter the properties of the object within the procedure. When you have a const argument, you cannot then pass this to another procedure by reference, because the procedure presumably does this so it can alter its value. Quote>Thank you all for your assistance :-) Cameron |
1. Saving Bitmaps, Strings and Integers to a binary file
3. It's not bad canned meat...
4. Problems saving TStringList object
5. Saving and loading TStringList problem
7. save/load TStringList to a database field!???
8. Saving a TStringList to a shared Unix directory fails
9. Saving TStringList with objects to a stream
10. Get strings from a buffer to TStringList or TStringStream