Solved

How to have my program ask for input?

Posted on 2007-11-30
3
163 Views
Last Modified: 2010-04-21
Hi Folks!

I have about 20 questions to ask. For example:

1.Whats the best Delphi resource on the internet?
2.How many questions did you ask already?
3.Do you ever answer questions yourself?
4. and so on.....

Ofcourse it should report the answers, preferrably in a simple text document, prefixed by the questions. Like this:

1.Whats the best Delphi resource on the internet?
EE ofcourse!!
2.How Many questions did you ask already?
A billion!

Now there must be a way to feed questions (by using textdocument) to the program withouth a message dialog for each question.....and still collect all answers....who can help me out here? (sample code please)

Kindest regards,

Dweeeeeeepsta

0
Comment
Question by:PeterdeB
  • 2
3 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 20385204
well, it depends on how you feed the data, or more better said, in what format you have the questions.

for exmaple, if you have the questions in one text document, one question per line, you can do something like in the attached code (written directly in the browser but should work just fine. let mw know if it doesn't; I'll then fire up an IDE to test it :P

is this something that you are looking for? if not, I'll need more detail explanation on what youa re trying to do.


var s,t:tstringlist;
    i:integer;
    a:string;
begin
  s:=tstringlist.create;
  try
    t:=tstringlist.create;
    try
      s.loadfromfile('questions.txt');
      for i:=1 to s.count do
      begin
        if not InputQuery('Give your answer', s[i-1], a) then
          a:='';// no answer given
        t.add(s[i-1]);// store question
        t.add(a);// store answer
      end;
    finally
      freeandnil(t);
    end;
  finally
    freeandnil(s);
  end;
end;

Open in new window

0
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 20385208
forgot to 'save" :)
var s,t:tstringlist;
    i:integer;
    a:string;
begin
  s:=tstringlist.create;
  try
    t:=tstringlist.create;
    try
      s.loadfromfile('questions.txt');
      for i:=1 to s.count do
      begin
        if not InputQuery('Give your answer', s[i-1], a) then
          a:='';// no answer given
        t.add(s[i-1]);// store question
        t.add(a);// store answer
      end;
      t.savetofile('list.txt');// save it to text file
    finally
      freeandnil(t);
    end;
  finally
    freeandnil(s);
  end;
end;

Open in new window

0
 

Author Closing Comment

by:PeterdeB
ID: 31412020
Haha bullls eye!!

Thank you sooo much my friend!

Regards,

Dweeeeeep ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question