Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- Quiz.pas - contains object structure of quiz questions and answers
- There are two major parts this unit contains:
- - TQuizList - contains a list of quizes which can be taken
- - TQuiz - contains copmlete quiz with questions and answers
- *)
- unit Quiz;
- interface
- uses
- System.Classes, System.SysUtils, System.Types, System.Generics.Collections,
- FMX.Graphics;
- type
- TQuizList = class;
- TQuizListItem = class;
- TQuiz = class;
- TQuizQuestionList = class;
- TQuizQuestion = class;
- TQuizQuestionContentList = class;
- TQuizQuestionContent = class;
- TQuizQuestionChoiceList = class;
- TQuizQuestionChoice = class;
- //Contains a list of TQuizListItem - typically listing results of quiz search
- TQuizList = class(TObject)
- private
- FItems: TObjectList<TQuizListItem>;
- function GetItem(Index: Integer): TQuizListItem;
- public
- constructor Create;
- destructor Destroy; override;
- function Count: Integer;
- procedure Clear;
- property Items[Index: Integer]: TQuizListItem read GetItem;
- end;
- //Contains basic information of a quiz to be displayed in a list
- TQuizListItem = class(TObject)
- private
- FOwner: TQuizList;
- FQuizId: Integer;
- FTitle: String;
- FDescription: TStringList;
- FCategory: String;
- FTags: TStringList;
- procedure SetCategory(const Value: String);
- procedure SetTitle(const Value: String);
- procedure SetQuizId(const Value: Integer);
- function GetTags: TStrings;
- procedure SetTags(const Value: TStrings);
- function GetDescription: TStrings;
- procedure SetDescription(const Value: TStrings);
- public
- constructor Create(AOwner: TQuizList);
- destructor Destroy; override;
- //Unique identifier of a particular quiz
- property QuizId: Integer read FQuizId write SetQuizId;
- //Display title of the quiz
- property Title: String read FTitle write SetTitle;
- //Detailed multi-line description of the quiz
- property Description: TStrings read GetDescription write SetDescription;
- //Category of the quiz
- property Category: String read FCategory write SetCategory;
- //Specific tags related to the quiz
- property Tags: TStrings read GetTags write SetTags;
- end;
- //Contains detailed information of a quiz, including questions and answers
- TQuiz = class(TObject)
- private
- FTitle: String;
- FCategory: String;
- FQuestions: TQuizQuestionList;
- FQuizId: Integer;
- procedure SetCategory(const Value: String);
- procedure SetTitle(const Value: String);
- procedure SetQuizId(const Value: Integer);
- public
- constructor Create;
- destructor Destroy; override;
- property QuizId: Integer read FQuizId write SetQuizId;
- property Title: String read FTitle write SetTitle;
- property Category: String read FCategory write SetCategory;
- property Questions: TQuizQuestionList read FQuestions;
- end;
- //Contains list of all questions in a quiz, including answers
- TQuizQuestionList = class(TObject)
- private
- FOwner: TQuiz;
- FTotalCount: Integer;
- FItems: TObjectList<TQuizQuestion>;
- function GetItem(Index: Integer): TQuizQuestion;
- public
- constructor Create(AOwner: TQuiz);
- destructor Destroy; override;
- function LoadedCount: Integer;
- function TotalCount: Integer;
- function LoadNext: TQuizQuestion;
- property Items[Index: Integer]: TQuizQuestion read GetItem; default;
- end;
- //Contains details of a quiz question, including content variation and answer
- TQuizQuestion = class(TObject)
- private
- FOwner: TQuizQuestionList;
- FQuestionId: Integer;
- FContents: TQuizQuestionContentList;
- FChoices: TQuizQuestionChoiceList;
- FCorrectAnswerId: Integer;
- FSelectedAnswerId: Integer;
- procedure SetQuestionId(const Value: Integer);
- public
- constructor Create(AOwner: TQuizQuestionList);
- destructor Destroy; override;
- property QuestionId: Integer read FQuestionId write SetQuestionId;
- function CorrectAnswer: TQuizQuestionChoice;
- function SelectedAnswer: TQuizQuestionChoice;
- end;
- //Contains list of content variations of a question
- TQuizQuestionContentList = class(TObject)
- private
- FOwner: TQuizQuestion;
- FItems: TObjectList<TQuizQuestionContent>;
- public
- constructor Create(AOwner: TQuizQuestion);
- destructor Destroy; override;
- end;
- //Contains a single variation of a single question
- TQuizQuestionContent = class(TObject)
- private
- FOwner: TQuizQuestionContentList;
- FContent: TStringList;
- function GetContent: TStrings;
- procedure SetContent(const Value: TStrings);
- public
- constructor Create(AOwner: TQuizQuestionContentList);
- destructor Destroy; override;
- property Content: TStrings read GetContent write SetContent;
- end;
- //Contains all possible multiple choice answers to a question
- TQuizQuestionChoiceList = class(TObject)
- private
- FOwner: TQuizQuestion;
- FItems: TObjectList<TQuizQuestionChoice>;
- public
- constructor Create(AOwner: TQuizQuestion);
- destructor Destroy; override;
- function Count: Integer;
- end;
- //Contains a single multiple choice answer to a question
- TQuizQuestionChoice = class(TObject)
- private
- FOwner: TQuizQuestionChoiceList;
- FText: String;
- FPicture: TBitmap;
- public
- constructor Create(AOwner: TQuizQuestionChoiceList);
- destructor Destroy; override;
- end;
- implementation
- { TQuizList }
- constructor TQuizList.Create;
- begin
- FItems:= TObjectList<TQuizListItem>.Create(True);
- end;
- destructor TQuizList.Destroy;
- begin
- FItems.DisposeOf;
- inherited;
- end;
- function TQuizList.GetItem(Index: Integer): TQuizListItem;
- begin
- Result:= FItems[Index];
- end;
- procedure TQuizList.Clear;
- begin
- FItems.Clear;
- end;
- function TQuizList.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- { TQuizListItem }
- constructor TQuizListItem.Create(AOwner: TQuizList);
- begin
- FOwner:= AOwner;
- FDescription:= TStringList.Create;
- FTags:= TStringList.Create;
- end;
- destructor TQuizListItem.Destroy;
- begin
- FTags.DisposeOf;
- FDescription.DisposeOf;
- inherited;
- end;
- function TQuizListItem.GetDescription: TStrings;
- begin
- Result:= TStrings(FDescription);
- end;
- function TQuizListItem.GetTags: TStrings;
- begin
- Result:= TStrings(FTags);
- end;
- procedure TQuizListItem.SetCategory(const Value: String);
- begin
- FCategory := Value;
- end;
- procedure TQuizListItem.SetDescription(const Value: TStrings);
- begin
- FDescription.Assign(Value);
- end;
- procedure TQuizListItem.SetQuizId(const Value: Integer);
- begin
- FQuizId := Value;
- end;
- procedure TQuizListItem.SetTags(const Value: TStrings);
- begin
- FTags.Assign(Value);
- end;
- procedure TQuizListItem.SetTitle(const Value: String);
- begin
- FTitle := Value;
- end;
- { TQuiz }
- constructor TQuiz.Create;
- begin
- FQuestions:= TQuizQuestionList.Create(Self);
- end;
- destructor TQuiz.Destroy;
- begin
- FQuestions.DisposeOf;
- inherited;
- end;
- procedure TQuiz.SetCategory(const Value: String);
- begin
- FCategory := Value;
- end;
- procedure TQuiz.SetQuizId(const Value: Integer);
- begin
- FQuizId := Value;
- end;
- procedure TQuiz.SetTitle(const Value: String);
- begin
- FTitle := Value;
- end;
- { TQuizQuestionList }
- constructor TQuizQuestionList.Create(AOwner: TQuiz);
- begin
- FOwner:= AOwner;
- FItems:= TObjectList<TQuizQuestion>.Create(True);
- end;
- destructor TQuizQuestionList.Destroy;
- begin
- FItems.DisposeOf;
- inherited;
- end;
- function TQuizQuestionList.GetItem(Index: Integer): TQuizQuestion;
- begin
- Result:= FItems[Index];
- end;
- function TQuizQuestionList.LoadedCount: Integer;
- begin
- Result:= FItems.Count;
- end;
- function TQuizQuestionList.LoadNext: TQuizQuestion;
- begin
- //TODO: Execute event which requests next question to be loaded
- end;
- function TQuizQuestionList.TotalCount: Integer;
- begin
- Result:= FTotalCount;
- end;
- { TQuizQuestion }
- constructor TQuizQuestion.Create(AOwner: TQuizQuestionList);
- begin
- FOwner:= AOwner;
- FContents:= TQuizQuestionContentList.Create;
- FChoices:= TQuizQuestionChoiceList.Create(Self)
- end;
- destructor TQuizQuestion.Destroy;
- begin
- FChoices.DisposeOf;
- FContents.DisposeOf;
- inherited;
- end;
- procedure TQuizQuestion.SetQuestionId(const Value: Integer);
- begin
- FQuestionId := Value;
- end;
- function TQuizQuestion.CorrectAnswer: TQuizQuestionChoice;
- var
- X: Integer;
- begin
- Result:= nil;
- for X := 0 to FChoices.Count-1 do begin
- end;
- end;
- function TQuizQuestion.SelectedAnswer: TQuizQuestionChoice;
- begin
- end;
- { TQuizQuestionContentList }
- constructor TQuizQuestionContentList.Create(AOwner: TQuizQuestion);
- begin
- FOwner:= AOwner;
- FItems:= TObjectList<TQuizQuestionContent>.Create(True);
- end;
- destructor TQuizQuestionContentList.Destroy;
- begin
- FItems.DisposeOf;
- inherited;
- end;
- { TQuizQuestionContent }
- constructor TQuizQuestionContent.Create(AOwner: TQuizQuestionContentList);
- begin
- FOwner:= AOwner;
- FContent:= TStringList.Create;
- end;
- destructor TQuizQuestionContent.Destroy;
- begin
- FContent.DisposeOf;
- inherited;
- end;
- function TQuizQuestionContent.GetContent: TStrings;
- begin
- Result:= TStrings(FContent);
- end;
- procedure TQuizQuestionContent.SetContent(const Value: TStrings);
- begin
- FContent.Assign(Value);
- end;
- { TQuizQuestionChoiceList }
- constructor TQuizQuestionChoiceList.Create(AOwner: TQuizQuestion);
- begin
- FOwner:= AOwner;
- end;
- destructor TQuizQuestionChoiceList.Destroy;
- begin
- inherited;
- end;
- function TQuizQuestionChoiceList.Count: Integer;
- begin
- Result:= Fitems.Count;
- end;
- { TQuizQuestionChoice }
- constructor TQuizQuestionChoice.Create(AOwner: TQuizQuestionChoiceList);
- begin
- FOwner:= AOwner;
- end;
- destructor TQuizQuestionChoice.Destroy;
- begin
- inherited;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment