Currently, i am working with some exercises with Pascal's unit. I try to create my own Readln but unsuccessful.

Unit DOCXAU;
INTERFACE
uses crt;
       TYPE  xau= STRING[100];
      var  c : char;
        s : xau;
        
       function nhap : xau;
IMPLEMENTATION
       function nhap : xau;
                   begin
                     s:='';
                     repeat
                     c:=ReadKey;
                     if ((c=#8) and (s<>''))       then
                        begin
                             delete(s,length(s),1);
                         end;
                     if ((c<>#8) and (c<>#13)) then
                        begin
                             write(c);
                             s:=s+c
                        end;
                     until c=#13;
                        nhap:=s;
                   end;
END.

Otherwise the final result is acceptable but when backspacing the cursor goes back with undeleted character.

Really needs suggestions..

Thanks in advance

Daravuth KEU

Member Avatar for Micheus

vuthcam, save the cursor pos (GetX and GetY) and use GotoXY to replace to the correct pos again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.