I made a square consisting of 4x4 edits. Each edit displays but one character.
If I click on an edit, I want its background to change to clRed instead of the default clWhite, unless it already is clRed, then it is supposed to change into clWhite.
Now the hard part:)
I have a label on that form (lblword) and its caption should reflect all the characters of the edits of which the background is colored clRed. If the clicking turns an edits background into clWhite again, that edits character should be removed.
edit1.text := 'A'
edit2.text := 'B'
edit3.text := 'C'
edit4.text := 'D'
Clicking on edit1 edit2 edit3 and edit4 (in the order clicked) should turn lblword.caption into: ABCD, that is if all these edits backgrounds are clRed.
Now I can't get this thing to work. The color swapping thingie aint the problem but the character adding\removing surely is. If all the backgrounds of all edits are clWhite the lblword.caption should be empty. The first of the edits to be clicked, turning its background into clRed, would then turn the lblword.caption into that edits text. If another edit is clicked and turned clRed that edits character should be added to the lblword.caption. If the last clicked edit of which the background is clRed is clicked again, its background should turn into clWhite and its character should be removed from the lblword.caption.
When the lblword.caption is equal to some predefined string, the fun is over and the lblword.caption should be blanked and all the edits backgrounds should be clWhite again.
Btw > if a label suits better instead of the edits I wish to use, then that is ok.
My first issue, adding and removing the characters of clicked edits is the most important and I think its possible to do so. The second is of minor importance. Providing code which solves the first issue grants you the points.
Here's part of my code which handles the colorchanging thingie as well as the lblword.caption-changing-thingie (incorrectly btw):
//all of the edits use this procedure
var Edit: TEdit;
// Grab hold of the particular edit > there will be lots of them named from edit1 up to edit64 or more
Edit := FindComponent((Sender as Tedit).Name) as tEdit;
// here comes my attempt to prevent addition of this edits.text in case its red, since then it is already selected > it should
// now change into clWhite and do nothing, I think (?) ,furthermore if its clWhite it should turn into clRed and continue here
if Edit.Color = clRed then exit else
edit.color := clRed;
//add this edits text to the lblword.caption
lblword.caption := lblword.Caption + edit.text;
//compare the 'created' word with some predefined string and if they match the fun is over
if lblword.Caption = SomePredefinedStringieThingie then
Doubleclicking should reset all edits backgrounds to clWhite and blank the lblword.caption, that part works to my satisfaction (hoera hoera! ;)
Every editclick adds its character to my lblword.caption and my attempt to prevent that by using its current color
resulted in nothing.
Now if you need more info let me know, I'm pretty determined to get this thing working one way or the other (the removing\adding thingie I mean)
Please modify the provided code or add or remove what should not be there and comment it well because it is obvious to me I am missing an important part here but even after searching my room for a couple of hours still no trace of it :)
Ps Bonus >Another thing I'm curious about is whether it is possible to drag over the different edits and let that drag do the color change as well as altering the lblword.caption into the 'dragselected edit characters' > I saw that behaviour at work in a word search puzzle, some java class file. Now this dragging thingie is not the important thing of this project, just something I'm curious about as to whether its possible, cause I doubt that.