Board index » delphi » Read only 10 char

Read only 10 char

I have made a program that askes the User a lot of questions like This

Question 1........:
Question 2........:
Question 3........:

and then the user aswers besides the questions.

And then my question is how do i make it so that the answer can't be
longer than the screen size

answersize = screensize(80 char) - question[1];

Please help me!!

 

Re:Read only 10 char


Quote
> I have made a program that askes the User a lot of questions like This

> Question 1........:
> Question 2........:
> Question 3........:

> and then the user aswers besides the questions.
> And then my question is how do i make it so that the answer can't be
> longer than the screen size

> answersize = screensize(80 char) - question[1];

   Use ReadKey to do your screen I/o:
procedure MYREAD (var ST : string; Q : Byte);  { internal string }
var C1,C2 : char;
begin
  ST := '';                           { initialize string length }
  repeat
    C1 := ReadKey;
    case C1 of
      #27  : begin                                      { escape }
             end;
      #00  : begin
               C2 := ReadKey;                  { fetch scan code }
               case C2 of
                 #59  : ;                                   { F1 }
                 #60  : ;                                   { F2 }
                 #61  : ;                                   { F3 }
                 #62  : ;                                   { F4 }
                 #63  : ;                                   { F5 }
                 #71  : ;                                 { Home }
                 #79  : ;                                  { End }
                 #72  : ;                             { Up Arrow }
                 #80  : ;                           { Down Arrow }
                 #108 : ;                               { Alt-F5 }
                 else   begin                       { all others }
                        end
               end  { case }
             end;
      #13  : ;                                             { C/R }
      #08  : begin                                   { Backspace }
               if Length(ST) > 0 then
                 begin
                   Dec (ST[0]);                { truncate string }
                   Write (#08#32#08);
                 end;
             end;
      else   begin                            { normal character }
               ST := ST+C1;    { concatenate character to string }
               Write (C1);
             end
    end;  { case }
  until (C1 = #13) or (Length(ST) >= Q)
end;  { MYREAD }

Re:Read only 10 char


Quote
>I have made a program that askes the User a lot of questions like This

>Question 1........:
>Question 2........:
>Question 3........:

>and then the user aswers besides the questions.

>And then my question is how do i make it so that the answer can't be
>longer than the screen size
>answersize = screensize(80 char) - question[1];

I've written a neat routine, which is even able to work with
prefilled strings. Home/End/Del are also useable:

function extreadln(maxchars,posx : word;var s2 : string) : boolean;
{read a line (like readln) from screen
maxchars : maximum amount of chars to read
posx     : position (cursor) in the text should be =>1
s2       : string where to read in (can be prefilled)}
var
  chars,i,width    : integer;
  ch,lch           : char;
  s                : string;
  x1,y1            : word;

procedure delete2(var s : string;chpos,num : byte);
begin
  system.delete(s,chpos,num);
  insert(' ',s,maxchars-chpos);
end;

procedure showtxt;
begin
  gotoxy(x1,y1);
  write(s);
  gotoxy(x1+posx-1,y1);
end;

begin
  x1 := wherex;
  y1 := wherey;
  chars := length(s2);
  s := s2;
  for i := 0 to 80-length(s2) do s := s + ' ';
  fillchar(s2[1],maxchars,ord('T'));
  s2[0] := chr(maxchars);
  fillchar(s2[0],80,0);
  lch := #1;
  showtxt;
  repeat
    if keypressed then begin
      lch := ch;
      ch := readkey
    end else ch := #1;

    if (ord(ch)> 1)and(lch <> #0) then
    case ch of
      #8  : if posx > 1 then begin
dec(chars);dec(posx);delete2(s,posx,1);showtxt;end;
  #13,#27 : begin;for i := 1 to chars do s2 := s2 + s[i];end;
     else if chars < maxchars then begin
       inc(chars);inc(posx); insert(ch,s,posx-1);
       showtxt;
       end;
    end;
    if (ch <> #1)and(lch = #0) then begin
      case ch of
        #71 : begin posx := 1;showtxt;end;
        #79 : begin posx := chars+1;showtxt;end;
        #75 : if posx > 1 then begin;dec(posx);showtxt;end;
        #77 : if posx <= chars then begin;inc(posx);showtxt;end;
        #83 :
 if posx <= chars then begin dec(chars);delete2(s,posx,1);showtxt;end;
       else lch := #1;
      end;
    end;
  until (ch = #27)or(ch = #13);
  writeln;
  if ch = #27 then extreadln := false else extreadln := true;
end;

Bye,
Stefan
---
please remove the P in my email-adress to answer me
take a look @ my homepage: http://sourcenet.home.pages.de/

Other Threads