Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 22nd, 2005, 03:45 PM
sma_soft sma_soft is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Location: Iran
Posts: 2 sma_soft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 42 sec
Reputation Power: 0
Send a message via MSN to sma_soft Send a message via Yahoo to sma_soft
Question NameValueCollection Equivalent in Delphi 6.0

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.

Reply With Quote
  #2  
Old October 22nd, 2005, 10:37 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,713 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 21 m 11 sec
Reputation Power: 1179
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > NameValueCollection Equivalent in Delphi 6.0


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT