给你个例子。
procedure TFormMain.MenuVisible(Query : tQuery);
begin
with Query do
begin
Close;
SQL.Clear;
SQL.Add('select distinct ServiceID from table where ServiceID <> ''0''');
Open;
if RecordCount = 0 then
Exit;
First;
while not eof do
begin
SubMenuItemVisble(FieldValues['ServiceID']);
Next;
end;
end;
end;