显示特定类型的所有变量

时间:2018-04-25 04:45:10

标签: pascal freepascal

我想在WriteFoodMenu中创建一个菜单,让用户显示所有可用选项(目前WriteLnWriteFoodMenu中执行的操作,或仅显示所选内容的选项场地位于。

因此,例如,如果用户选择“面包店”,

WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue);

仅显示场地是面包店的选项。

编辑:如果我需要包含其他内容,请告诉我

type 
Venues =(cafe, resteraunt, bakery, milkbar, fastfood);

Mfood = record
foodtype, chef: string
venue: Venues;
end;


function FoodType(prompt: String): Venues;
    var
        selection: Integer;
    begin
        WriteLn('Venues:');
        WriteLn('  1. Cafe');
        WriteLn('  2. Restaurant');
        WriteLn('  3. Bakery');
        WriteLn('  4. Milkbar');
        WriteLn('  5. FastFood');

        selection := ReadIntegerRange('Select a venue (1 - 5): ', 1, 5);
        result := Venues(selection - 1);
    end;

    procedure WriteFoodMenu(MFood: MFood);
    begin
    WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue);
    end;

1 个答案:

答案 0 :(得分:1)

您必须选择$xml = @' <?xml version="1.0" encoding="utf-8" ?> <Cash Activities> '@; $rows = $html.DocumentElement.SelectNodes('//tr'); foreach ($row in $rows) { if ($row.GetAttribute('class') -eq 'c12') { $xml += "`t<Cash Activity>`n"; $spans = $row.SelectNodes('.//descendant::span[@class]'); if ($spans.Count -eq 2) { $xml += "`t`t<Activity>$($spans[0].InnerText.Trim())</Activity>`n"; $xml += "`t`t<Balance>$($spans[1].InnerText.Trim())</Balance>`n"; } $xml += "`t</Cash Activity>`n"; } } $xml += @' </Cash Activities> '@;

Venues

仅当您将所需的场地传递给程序时才有效。现在您可以获得MFoods列表:

procedure WriteFoodMenu(Venue: Venues; MFood: MFood);
begin
  if MFood.venue = Venue then
    WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue);
end;

请注意,在显示菜单之前显示传递给const Foods: array[0..numOfFoods - 1] of MFood = ( (FoodType: 'Spaghetti'; Chef: 'Luigi'; Venue: resteraunt), ( etc...), // etc... ( etc...) ); ... Venue := FoodType('Select a venue'); for I := Low(Foods) to High(Foods) do WriteFoodMenu(Venue, Foods[I]); 的提示是有意义的。您目前根本没有使用提示。