Board index » delphi » Problem with Arrays of strings - prob.txt [1/1]

Problem with Arrays of strings - prob.txt [1/1]

Quote
You wrote:
>Ok after that I have some more minor questions... using my basic c:=readkey
>and case statement ... how to use the Keypad or arrows to move the cursor
>around with inc/dec x/y ... ?

        Well, i assume the code u use is something like this....

<snip>

const
        up=#72
        down=#80
        left=#75
        right=#77

{Just in case u don't know...#xx is another way of saying "ord(c)=xx"}

var c:char;

begin
        c:=readkey;
        if c=up then goup;
        if c=down then godown;
        if c=left then goleft;
        if c=right then goright;
end.

<snip>

        If this is what you're doing, then i can see the problem. I don't know the
"official" term for it (i think it's just extended ascii or shifted characters), but what it is
is that the character u read from such a key will be a #0 (null). If u read ANOTHER
key, u will get a #77,#72, etc... Soooooo...what u need to do to the above code is
the following...

<snip>

const
        up=#72
        down=#80
        left=#75
        right=#77

var c:char;

begin
        c:=readkey;
        if c=#0 then {or "if ord(c)=0 then"}
        begin {a case statement would be better here, but i wanted to relate it to}
        `           {the other coding}
                c:=readkey {!!**<< here it is!!}
                if c=up then goup;
                if c=down then godown;
                if c=left then goleft;
                if c=right then goright;
        end; {c=#0}
end.

<snip>

        'Hope this helps you! Please ask if any of this isn't clear!

 

Re:Problem with Arrays of strings - prob.txt [1/1]


Here's what I use:

      Repeat
        If KeyPressed Then Begin
          ch := ReadKey;
          if (ch = #0) And (KeyPressed)
            then ch := ReadKey;
          Case ch of
            #72: Move_up;
            #80: Move_down;
            #75: Move_left;
            #77: Move_right
          End;    {case}
        End      {Keypressed = true}
      Until ch in [#113, #27];   {exit on 'q' or ESC }

if you want to respond to different keys, just add their return codes to
the case statement.

Here's a quick and dirty program so you can find the key code responses.:

program keys;
uses crt,dos;
var ch: char;

begin
  repeat
    ch := readkey;
    if keypressed and (ch = #0) then ch := readkey;
    writeln (ord (ch));
  until ch = #27;
end.

run this, and hit ESC to quit.

Hope this helps.

Ken

In article <4d01ns$...@lantana.singnet.com.sg>, pma...@Singnet.com.sg
says...
--
Views expressed herein are not necessarily the views
of Ontrack Computer Systems, Inc. or Ontrack Data Recovery, Inc.
*******************************************************************
* Ken Stieers               |  Minneapolis - 1.800.872.2599       *
* AV Research/Apps. Eng.    |  Los Angeles - 1.800.752.7557       *
* Ontrack Computer Systems  |  Washington, D.C. - 1.800.650.2410  *
* Ontrack Data Recovery     |  London - 0800 24 39 96             *
* Eden Prarie, MN           |  Japan - 81.429.32-6365             *
*******************************************************************

Other Threads