|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I used the NameValueCollection class in the .NET Framework for storing NameValue Data. An example of that, is the Request.QueryString object in ASP.NET Programming. But I want to know that what is the equivalent of this Object in Delphi 6.0 ? As you know, Delphi's Prior to 8.0 don't support .NET Framework. I used TStringList class, but it stores strings only with their index numbers. And can't index the values by String Names. Anyone can help ? thanks all. |
|
#2
|
||||
|
||||
|
Erm, you can use TStringList actually. Unfortunately, I don't have a Delphi compiler installed on this particular computer, otherwise I'd give you an exact example. Here's how to do it off the top of my head.
1. Note that TStringList has an AddObject method, as well as an Add method. You can use AddObject to associate an object with a string. 2. The trick with AddObject is that the second object must be a descendant of TObject. This is no problem, since we can declare our value type as a TObject descendant: Code:
type:
TMyValue = class(TObject)
public
nValue : integer;
end;
This is assuming that the data we want to store (nValue) is an integer. It can be a more complex type if you like (say, a bunch of values). 3. Then to add an item to the StringList, do something like this: Code:
procedure TForm1.AddNameValue(sName: string; nValue: integer);
var
oMyValue : TMyValue;
begin
oMyValue := TMyValue.Create;
oMyValue.nValue := nValue;
stl.AddObject(sName, oMyValue);
end;
4. Now to get a value off the StringList, you can get the object associated with the string and cast it back to a TMyValue and extract the values from the object. It might be faster if you set StringList.sorted := true, so that the stringlist is sorted to start with. 5. To clear the list, you go through each entry in the stringlist, get the object (via the StringList.Objects[i] method) and free each one first. Then clear the stringlist. Hope this helps.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > NameValueCollection Equivalent in Delphi 6.0 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|