Модераторы: volvo877, Snowy, MetalFan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Редактирование строки - как в текстовом поле! 
:(
    Опции темы
godsgame
  Дата 20.4.2007, 14:33 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 241
Регистрация: 29.8.2005

Репутация: нет
Всего: нет



Помогите пожалуйста реализовать такое:

В ф-цию передаем строковую переменную (стринг) и нужно сделать:
1) Вывод этой строки на экран + редактирование
2) Т.е можно передвигать курсор по этой строке стрелками
3) Клавиши Делите и БэкСпейс удаляют символы по сторонам (ну как в обыном текстовом поле)
4) Энтер - подтверждением, т.е выход из цикла (предположительно, там должен быть цикл).
5) Эскейп - отмена всех действий.
6) Если можно отловить Хоме и Энд - то переносится курсор в начало/конец строки.
7) остальные символы считаеются за обычные символы, т.е дописываются на место курсора.

Спрашиваю, потому что не совсем умею работать с символами... вобщем шаблон примерно такой:

Код

function editString ( var str : String );
var
    strBackup : String;
    sim       :  Char;

begin

    strBackup := str;

    write ( str );

    While ( 1 ) do
    begin

        sim := readKey;

        { если ESC }
        if ( ... ) then
        begin
            str := strBackup;
            break;
        end
        { если Delete }
        else if ( ... ) then
        begin
        
        end
        { если Backspace }
        else if ( ... ) then
        begin
        
        end
        { если Home }
        else if ( ... ) then
        begin
        
        end
        { если End }
        else if ( ... ) then
        begin
        
        end
        { если Enter}
        else if ( ... ) then
        begin
            break; {???}
        end
        { drugoj simbol }
        else
        begin
            
        end;
    end;

end;


Помогите, пожалуйста... очень надо
PM MAIL   Вверх
Fighter
Дата 20.4.2007, 23:04 (ссылка) |    (голосов:1) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 810
Регистрация: 5.1.2005

Репутация: нет
Всего: 2



Попробуй такой вариант

Код

Uses crt;

const VK_ENTER = 13;
const VK_ESC   = 27;
const VK_EX_UP = 72;
const VK_EX_DOWN = 80;
const VK_EX_LEFT = 75;
const VK_EX_RIGHT = 77;
const VK_SPACE = 32;
const VK_BACKSPACE = 8;
const VK_EX_INSERT = 82;
const VK_EX_DELETE = 83;
const VK_EX_HOME = 71;
const VK_EX_END = 79;

function EditStr(str: string): string;
var
  stop: boolean;
  key, ex_key: integer;
  oldStr: string;
  x,y: integer;
  insertMode: boolean;
begin
  oldStr := str;
  clrscr;
  write(str);
  x := whereX;
  y := whereY;
  stop := false;
  insertMode := true;
  if insertMode then
  begin
    gotoxy(60, 25);
    write('Insert mode on')
  end
  else
  begin
    gotoxy(60, 25);
    write('Insert mode off')
  end;
  gotoxy(x,y);
  while not stop do
  begin
    if KeyPressed then
    begin
      x := whereX;
      y := whereY;
      key := Ord(ReadKey);
      if key = 0 then
      begin
        ex_key := ord(readkey);
        if ex_key = VK_EX_LEFT then
        begin
          if x > 1 then
            x := x - 1
        end
        else if ex_key = VK_EX_RIGHT then
        begin
          if x <= length(str) then
            x := x + 1;
        end
        else if ex_key = VK_EX_HOME then
        begin
          x := 1;
        end
        else if ex_key = VK_EX_END then
        begin
          x := length(str) + 1;
        end
        else if ex_key = VK_EX_INSERT then
        begin
          insertMode := not InsertMode;
        end
        else if ex_key = VK_EX_DELETE then
        begin
          if x <= length(str) then
            delete(str, x, 1);
        end
      end
      else
      begin
        if key = VK_ENTER then
        begin
          stop := true;
        end
        else if key = VK_ESC then
        begin
          str := oldStr;
          stop := true;
        end
        else if key = VK_BACKSPACE then
        begin
          if x > 1 then
          begin
            delete(str, x-1, 1);
            x := x - 1;
          end;
        end
        else if (key in [ord('a')..ord('z')]) or (key in [ord('A')..ord('Z')]) or
        (key in [128..159]) or (key in [ord(' ')..ord('¯')]) or
        (key in [ord('à')..ord('ï')]) or (key = 32) then
        begin
          if insertMode then
          begin
            insert(chr(key), str, x);
            x := x + 1
          end
          else
          begin
            delete(str, x, 1);
            insert(chr(key), str, x);
            x := x + 1;
          end;
        end;
      end;
      clrscr;
      if insertMode then
      begin
        gotoxy(60, 25);
        write('Insert mode on')
      end
      else
      begin
        gotoxy(60, 25);
        write('Insert mode off')
      end;
      gotoxy(1,1);
      write(str);
      gotoxy(x,y);
    end;
  end;
  EditStr := str;
end;

var
  s: string;


begin
  clrscr;
  write('Enter the string: ');
  readln(s);
  s := EditStr(s);
  writeln;
  writeln('The S = ', s);
  readkey;
end.



PM MAIL   Вверх
godsgame
  Дата 21.4.2007, 18:01 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 241
Регистрация: 29.8.2005

Репутация: нет
Всего: нет



Fighter, 

почти то что надо, только там была проблема, что он все стирал и начинал с 1,1... вобщем я покопался и исправил это:

Код

Uses crt;

const VK_ENTER = 13;
const VK_ESC   = 27;
const VK_EX_UP = 72;
const VK_EX_DOWN = 80;
const VK_EX_LEFT = 75;
const VK_EX_RIGHT = 77;
const VK_SPACE = 32;
const VK_BACKSPACE = 8;
const VK_EX_INSERT = 82;
const VK_EX_DELETE = 83;
const VK_EX_HOME = 71;
const VK_EX_END = 79;

function EditStr(str: string): string;
var
    stop: boolean;
    key, ex_key: integer;
    oldStr: string;
    x,y,mx: integer;
    insertMode: boolean;
    start_x : integer;

    procedure myClean ( s1 : string; s2 : string );
    var
        l1 : integer;
        l2 : integer;
        l  : integer;
        i  : integer;

    begin
        l1 := length ( s1 );
        l2 := length ( s2 );

        if ( l1 > l2 ) then
            l := l1
        else
            l := l2;

        for i := 1 to l do
            write(' ');
    end;
begin

    oldStr := str;
    write(str);
    x := whereX;
    y := whereY;
    stop := false;
    insertMode := true;

    start_x := x - length ( str );
    gotoxy(x,y);

    while not stop do
    begin
        if KeyPressed then
        begin
            x := whereX;
            y := whereY;
            key := Ord(ReadKey);

            if key = 0 then
            begin
                ex_key := ord(readkey);
                if ex_key = VK_EX_LEFT then
                begin
                    if x > 1 then
                        x := x - 1
                end
                else if ex_key = VK_EX_RIGHT then
                begin
                    if x <= length(str) then
                        x := x + 1;
                end
                else if ex_key = VK_EX_HOME then
                begin
                    x := 1;
                end
                else if ex_key = VK_EX_END then
                begin
                    x := length(str) + 1;
                end
                else if ex_key = VK_EX_INSERT then
                begin
                    insertMode := not InsertMode;
                end
                else if ex_key = VK_EX_DELETE then
                begin
                    if x <= length(str) then
                        delete(str, x, 1);
                end
            end
            else
            begin
                if key = VK_ENTER then
                begin
                    stop := true;
                end
                else if key = VK_ESC then
                begin
                    str := oldStr;
                    stop := true;
                end
                else if key = VK_BACKSPACE then
                begin
                    if x > 1 then
                    begin
                        delete(str, x-1, 1);
                        x := x - 1;
                    end;
                end
                else if (key in [ord('a')..ord('z')]) or (key in [ord('A')..ord('Z')]) or
                        (key in [128..159]) or (key in [ord(' ')..ord('?')]) or
                        (key in [ord('a')..ord('i')]) or (key = 32) then
                begin
                    if insertMode then
                    begin
                        insert(chr(key), str, x);
                        x := x + 1
                    end
                    else
                    begin
                        delete(str, x, 1);
                        insert(chr(key), str, x);
                        x := x + 1;
                    end;
                end;
            end;

            gotoxy(x,y);
            gotoxy(start_x,y);
            myClean ( str, oldStr );
            gotoxy(start_x,y);
            write(str);
            gotoxy(x,y);
        end;
    end;
    
    EditStr := str;
end;

var
  s: string;


begin
  clrscr;
  write('Enter the string: ');
  readln(s);
  s := EditStr(s);
  writeln;
  writeln('The S = ', s);
  readkey;
end.



огромное тебе спасибо, "+" с меня  smile 

Это сообщение отредактировал(а) godsgame - 21.4.2007, 18:04
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Delphi"
THandle
Rrader
volvo877

Запрещается!

1. Обсуждать и делится взломанными компонентами или программным обеспечением

2. Публиковать ссылки на варез

3. Оффтопить

  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь
  • 90% ответов на свои вопросы можно найти в DRKB (Delphi Russian Knowledge Base) - крупнейшем в рунете сборнике материалов по Дельфи

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, THandle, Rrader, volvo877.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Object Pascal: кроссплатформенные технологии | Следующая тема »


 




[ Время генерации скрипта: 0.0473 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.