I am using an edit box as a round counter. I would like when the text = 5 or 10 for it to show this message then it does some functions. but even when the round is 5 or 10, i never get this message ERoundChange is the OnChange event for the ERound(edit box) ; Any idea why its not working? I assume i am using Self wrong?
{Check if round is 5 or 10}
//-----------------------------------------------------
procedure TBaseGameForm.ERoundChange(Sender: TObject);
//-----------------------------------------------------
begin
if (self.Text = '5') or (self.Text = '10') then
begin
showmessage('checking stats for gryph locations on round: '+self.Text);
end;
end;
Also I change the round at the beginning of each players turn like so
ERound.Text := inttostr(Strtoint(ERound.Text)Mod 10+1);
Since
ERoundChangeis a method ofTBaseGameForm,Selfrefers to the current instance ofTBaseGameForm, that is, to the form, and not the edit box inside it.Hence,
Self.Textis the caption of the form, and not the text inside the edit box. If the edit box is namedEdit1, you should doYou could also do
since the control that caused the event is stored in the
Senderargument. But sinceSenderis declared asTObject, you need to cast it to the actualTEditwhich it is.[You could have figured this out yourself. Indeed, the procedure
TBaseGameForm.ERoundChangeitself has nothing to do with the edit control — sure, it is assigned to an event of this control, but of course you can assign it to other controls as well, and use it in any other way you like. Hence, by itself, it is only associated withTBaseGameForm, so really,Selfcouldn’t logically refer to anything else.]