Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

for loop

Status
Not open for further replies.

Spider

Programmer
Sep 3, 1998
3
US
hey can someone help me out with this. what does htis mean.. for loop control variable must have ordinal type ??

Question : string;
begin

for Question := 1 to 30 do
begin
if i = 'B' then
begin
Correct := Correct + 1;
Stop := Stop - 1;
ShowMessage ('Correct');
lblAnswers['B'].color := clRed;
end
else
begin
Stop := 5;
ShowMessage ('Incorrect');
lblAnswers['B'].color := clRed;
end;
end;
 
Hi Spider,

you declared Question as string, so for Question := ... does not work.
An ordinal type ist char, byte, integer aso.

Bye
Chris
 
hey cheers. now my program runs but it says that i might not have been initialised. any ideas ?

var Column : Integer;
var Row : Integer;
var i : Char;
begin
Row := 0;
Column := 0;
for i := 'A' to 'F' do
begin
cmdLetters:= TButton.Create(FrmQuiz);
with cmdLetters do
begin
Caption:= i;
Top := 25* Row;
Left := 25* Column;
Height := 25;
Width := 25;
OnClick := FrmQuiz.btnLetterClick;

cheers for any help :eek:)
 
Hi spider,

I dont know the reason, why delphi raises this warning, but if you are shure, there is no reason for such warning, you can ignore it.
 
I found that for string variables they need to be initialized before they are used in any manner in order to avoid the warning message you received. It seems Delphi does not recognize the FOR statement as initializing the string variable 'i'. If you are still concerned about the warning message, get rid of it by adding the line
i := ''; just before the FOR loop.
 
cheers for that guys. i have got it to compile now and run. thing is my program does not recognise the answers. no matter what answer you give it says that it is incorrect and it is then stuck in a loop. it gets to the 'Showmessage('incorrect') but then that won't go. it does not seem to be regonising i properly as it only gives incorrect no matter what you press. any ideas. it looks fine to me but not working properly. :eek:(
 
Hi spider,

I think that your program doesn't work is a problem in the event routine btnLetterClick.

Bye
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top