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 20th, 2004, 05:47 PM
dreamychris dreamychris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Devon
Posts: 8 dreamychris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 41 sec
Reputation Power: 0
Question Searching for a string within a StringGrid (for a board-games board clone)

Hey there,

I've been programming a string grid to display a variety of numbers in a pattern (this is used for replicating board games such as snakes and ladders where the numbers run to and fro)

I've just finished the board so that when I click the desired button, the stringgrid arranges itself how I want it to. However I do not now know how to search for the value of the String. For example somewhere in the grid is a number "47" however I do not know how to search for this number and replace the cell with "47" in with something like "Player 1 position."

It may be simple, it may be impossible. But any ideas?
(PS please tell me if im not making much sense!)

Reply With Quote
  #2  
Old October 20th, 2004, 06:03 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
Pretty easy actually. Note that the StringGrid has a property called Cols which returns a specific column as a TStrings. It also has a property called Rows, that returns a specific row as a TStrings object. Either way, a TStrings has an IndexOf() method to find a string within it. So, here's our method:

1. Go through all the columns of the stringgrid using the Cols property.
2. For each one, use IndexOf() to see if the string exists in this column. If it does, this is the row position of the item.
Code:
var
	nCol : integer;
	nRow : integer;
begin
	for nCol := 1 to StringGrid1.ColCount - 1 do
	begin
		nRow := StringGrid1.Cols[nCol].IndexOf('47');
		if (nRow > -1) then
			ShowMessage('Found it at Column: ' + IntToStr(nCol) + ' and Row: ' + IntToStr(nRow));
	end;
end;
__________________
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
  #3  
Old October 20th, 2004, 06:30 PM
dreamychris dreamychris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Devon
Posts: 8 dreamychris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 41 sec
Reputation Power: 0
Thanks alot, I spent a long while looking for a solution and the speed of your reply has been extremely helpful. Thanks again!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Searching for a string within a StringGrid (for a board-games board clone)


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 1 hosted by Hostway
Stay green...Green IT