Search code examples
pascalfreepascallazarus

Whenever specific button clicked it does something in Pascal


Hello. Can anyone help me with scanning buttons always and when I click specific one it does something even Im writing? I want to be filling a record with like 9 attributes but when Im atc. at fourth I want to close it. I tried some readkey stuff :

procedure searching();
var p:char;search:string='';
begin
     repeat
       p:=readkey();
       write(p);
       search+=chr(p);
       until (p=#27) or (p=#13);
       if (p=#27) then menu()
       else
       ...

but the problem was that it written some character it was not possible to erase it and I knew that backspacing and writing again made my search filled with characters I did not wanted in there. Couldn't find a topic about it in pascal so im trying here. Don't flame for english please. Hope you get what I meant, also English is maybe the problem I can't find it, whatever. Waiting for answer, Thanks, Maroš.


Solution

  • but the problem was that it written some character it was not possible to erase it

    Why not? Just handle #8 (backspace) and truncate your last character from the search string. You can use both System.Delete (by deleting the last character) and System.SetLength (by setting the length to current length - 1).