I need a help to create function that helps me to write text in labes and exchange some labels for edit

hidrau
hidrau used Ask the Experts™
on
Hello Guys,

I need to create an activity to my students.
I have a scrollbox in a form and from my table I will have a text.

I need to write all my text in my scrollbox with labels, but
For each line of my text I need to sort some words and exchange with edit so that
my students can listen to a type that reads the text and fill the edit with the correct
words that were hidden.

I need to create a system that I need to correct the words filled, so I was thinking to
have all words in a Stringlist and for each edit its tag will have a number that will
linked to stringlist so that I can make the correction.

I will have a button that will generate this activety, but each time I start the button, it
must generate a different activity, that is, hiding some words randonly.

I hope I could explain it
thanks very much
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Maybe a little bit more explanation could help ;-)

Author

Commented:
I am gonna give you an example:

I have a text, like this:

Heroes is an American science fiction drama television series, created by Tim Kring, which premiered on NBC on September 25, 2006. The show tells the story of several people who "thought they were like everyone else... until they woke with incredible abilities" such as telepathy, time travel and flight

So, it will be write in a scrollbox with labels, but randonly I will replace some words with edits.

Heroes is an American ________ fiction drama television ______, created by Tim Kring, which premiered on NBC on ________ 25, 2006. The show tells the story of ________ people who "thought they ______ like everyone else... until they woke with _______ abilities" such as _________, time travel and flight


science - series - September - several - were - incredible - telepathy

My students will have to listen to the text and fill the edits with the words which is missing.
When I change the from label to edit, I keep the words in a StringList so that I can correct
afterwards. So the first Edit in its tag will have a sequency nunmber that will correspond
to the sequence of my stringlist words. I will use the sequence to pick the word up and match
with Edit (what my student wrote). This must be put in a scrollbox so that be possible to scroll
the text when it is big.

Did you understand?
Hi,
I guess following function does what you want :


function CheckAnswers( frm: TForm ; tstr: TStrings ): Integer;
var
  intX: Integer;
begin
  Result := 0;
  for intX:=0 to frm.ControlCount-1 do
  begin
    if ( frm.Controls[intX] is TEdit ) then
      if tstr[ (frm.Controls[intX] as TEdit).Tag ] = (frm.Controls[intX] as TEdit).Text then
        Inc( Result );
  end;
end;



This functions justs checks every TEdit-Control on the given Form and when its value is the same as the value in the provided TStrings (on position = TEDit.Tag), then you have a correc tanswer.
So, at the end, the functions returns the amount of correct answers.

Hope this is more or less what you are lokking for.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Hi again,

I just improved the function. I made it a bit more generic + I put a bit of comment in it:

function TForm1.CheckAnswers( ctrl: TWinControl ; tstr: TStrings ): Integer;
var
  intX: Integer;
begin
  { By Defaul, assume there are no correct answers. }
  Result := 0;
  { Loop all TEdits of the provided WinControl (Like Panel, TabSheet, Form, ...) }
  for intX:=0 to ctrl.ControlCount-1 do
  begin
    { If the Text-Property of the currect TEdit is the same value of the one
      found in the TStrings, then we have a correct answer. Then we should
      increase the Result.
      To know which 'answer' of the TStrings we should use, we make use of the
      Tag-property of the current TEdit.
    }
    if ( ctrl.Controls[intX] is TEdit ) then
      if tstr[ (ctrl.Controls[intX] as TEdit).Tag ] = (ctrl.Controls[intX] as TEdit).Text then
        Inc( Result ); { Inclrease the Result. }
  end; { for intX:=0 to ctrl.ControlCount-1 do }
end;


So now you can provide any TWinControl as the first parameter. This makes it possible to e.g. have a TPageControl with 7 Tabsheets on it and have the TEdits spread over those separate TabSheets.

Then you can call the function like :
      CheckAnswers( TabSheet1, mmoCorrectAnswers.Lines );
OR
      CheckAnswers( Form1, mmoCorrectAnswers.Lines );
OR
      CheckAnswers( Panel1, mmoCorrectAnswers.Lines );
OR
      ....



Author

Commented:
thanks
Thank you for the points and the grade.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial