1

I'm having yet another problem with Delphi. I wrote a piece of code that should check if a field in a database table equals to 0, and if that is true, changes font color and caption of a certain button. It runs on creation of the main form. However, when I run the program, nothing happens - the program does not appear and I get no errors. I seriously don't know what's wrong, seems like some kind of an infinite loop.

Here's the code:

procedure TForm1.FormCreate(Sender: TObject);
begin
ADOTableStorage.First;
while not ADOTableStorage.Eof do
    If ADOTableStorage.FieldByName('amount').AsInteger = 0 then
        begin
        btStorage.Font.Color := clRed;
        btStorage.Caption := 'Some items are out of stock!';
        Break;
        end;
    ADOTableStorage.Next;
end;

Note: The ADOTableStorage table is a on the detail table in a Master-Detail connection.

Thanks!

Radiant
  • 47
  • 2
  • 10

1 Answers1

3

I guess you are missing a begin/end in the while loop. Try this.

procedure TForm1.FormCreate(Sender: TObject);
begin
  ADOTableStorage.First;
  while not ADOTableStorage.Eof do
  begin
    If ADOTableStorage.FieldByName('amount').AsInteger = 0 then
    begin
        btStorage.Font.Color := clRed;
        btStorage.Caption := 'Some items are out of stock!';
        Break;
    end;
    ADOTableStorage.Next;
  end;
end;
Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
  • Huh. That worked. Thank you, I am such a noob. I can't believe I didn't notice it. Thanks again! – Radiant May 23 '11 at 20:32