Sauté onions in olive oil until tender and translucent. Add ham and grated cheese. Combine sugar and flour with seasonings, and add to slightly beaten eggs. Add milk to egg mixture. Put sautéed onion, ham, and cheese in a pie shell; pour milk and egg mixture over onions. Bake in pre heated oven at 425 degrees for 35 minutes or until custard is set and golden brown. Serve warm.