Jump to content
Sign in to follow this  
Johansy

What should use: Stringlist, Advanced Record, Database or Tlist Class?

Recommended Posts

I am making an application that consists of a kind of mental test of several blocks of questions that are located in each application tabs, as the user is answering the question that considers each block the test is sum the numerical value that each question represents for the end, in dependence on the amount added, introduce the user with a certain to their own. I have tried to put the result that each question answered from each block in a Stringlist, saving in a text file for the end to sum everything and dependent on the value to answer to user based on the parameters of the test, but the problem is in that if the user wants to return and answer in each block another question as differing from the one previously answered, I must eliminate to the list the previously inserted numbers and instead putting the answer that answers the answer, which I think that a Stringlist is not the most suitable for this ... what would recommend to solve this roll?

Share this post


Link to post

Just in case the question still is open: I find it very hard to understand what exactly you are talking about. For instance, what does "introduce the user with a certain to their own." mean? Just guessing I would probably create a small class and use it in a generic TObjectList.

Share this post


Link to post

If your Delphi version is new enough to support generics:

Create a TDictionary where the key is the number (ID) of the question and the data is the number of points of the answer selected.

 

Store the ID of the question in the tag of the tab the question is on (assuming one tab holds one question, if not put each question
in some container which has a tag, it doesn't matter if that container is visible or not). Store the number of points associated with an
anwer to the question in the tag of the checkbox or radio button for the answer.

 

If somebody selects an answer look in the list if there is already some entry with hat question ID. If yes, remove it and add it again with
the new data or overwrite the data.

 

When the questionaire is finished iterate through the dictionary and count the points.

 

uses
  Generics.Collections;
  
type
  // first one is the key = question ID, last one the data asociated with the key in your case the points.
  TAnswerDict = Dictionary<integer, integer>;
  
var
  Answers:TAnswerDict;
  Pair: TPair;
  Points: Integer;
  
begin
  Answers := TAnswerDict.Create;
  
  try
    Answers.Add(1,3); 
    Answers.Add(2,1);
  
    Points := 0;
    for Pair in Answers do
      inc(Points, Pair.Value);
  finally
    Answers.Free;
  end;
end.  

The code has not been tested but it should be a starting point for you, if still relevant.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×