Solved

How to have my program ask for input?

Posted on 2007-11-30
3
158 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:ciuly
Comment Utility
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:
ciuly earned 500 total points
Comment Utility
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
Comment Utility
Haha bullls eye!!

Thank you sooo much my friend!

Regards,

Dweeeeeep ;-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now