Autor Beitrag
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Fr 25.06.04 15:13 
Hi!
Ich brauch mal hilfe bezüglich 'nem memo:
ich möchte 'nen keypress abfangen und ersetzen.
zum beispiel key='ö' -> an das memo wird oe angehängt.
oder key='2' -> 'zwei' !
(mit key := 'o'; key := 'e'; gehts ja net, da delphi nur den letzten wert zurückgibt..)
hat da jemand 'ne ahnung wie ich das am besten bewerkstellige ?
tia rizla
DelphiFreund
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 120

Win XP
D7 Enterprise
BeitragVerfasst: Fr 25.06.04 15:32 
Bin mir nicht sicher, aber vieleicht mit Ord('Ö') ?
rizla Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Fr 25.06.04 15:34 
brauche ja net den keycode sondern eher dass im memo statt "ö" "oe" angezeigt, gespeichert what ever wird.
aber trotzdem thx rz!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 25.06.04 15:40 
So sollte es gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = 'ö' then
  begin
    key := #0;
    memo1.text := memo1.text + 'oe';
    memo1.SelStart := Length(Memo1.Lines.Text);
  end;
end;

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
DelphiFreund
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 120

Win XP
D7 Enterprise
BeitragVerfasst: Fr 25.06.04 15:40 
Wie wärs, wenn du jedes mal wenn ein 'o' kommt Wert= true machst und wenn bei der nächsten Taste ein 'e' kommt die beiden letzten zeichen löscht und durch ein 'ö' ersetzt und Wert= false setzt. Und wenn kein 'e' kommt auch Wert= false

Gruß DelphiFreund
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Fr 25.06.04 15:43 
@Peter Lustig: Dann erhälst du doch "oeö" oder "öoe", je nach Vorgehensweise der Komponente ...
Evtl. also memo auf Readonly schalten und jeden Keypress manuell verarbeiten?

Cu,
Udontknow
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 25.06.04 15:45 
@Udontknow: Ich setze doch den key:=#0!

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Fr 25.06.04 15:50 
Peter setzt das oe einfach hintenran, was beim editieren des Texts hinderlich sein könnte. Habs mal "erweitert":
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var tmp: String;     // für insert
    oldcp: TPoint;   // alte caret position
begin
  oldcp := Memo1.CaretPos;
  tmp := Memo1.Lines.Strings[Memo1.caretpos.y];
  if Key = 'ö' then
  begin
    Insert('oe', tmp, Memo1.CaretPos.X+1);
    Key := #0;
    inc(oldcp.x, 2);   // alte caret pos ausbessern
  end;
  Memo1.Lines.Strings[Memo1.CaretPos.Y] := tmp;
  memo1.CaretPos := oldcp;
end;


raziel

//edit: fehlerle entdeckt und ausgebessert: caretpos darf nur geändert werden, wenn auch die eingabe geändert wurde.

_________________
JSXGraph
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Fr 25.06.04 15:58 
@Peter: Ach hast recht, bin völlig blind. :)

Cu,
Udontknow
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 25.06.04 16:01 
Zitat:
@Peter: Ach hast recht, bin völlig blind. :-)

Dafür habe ich das mit dem im Text einfügen völlig übersehen. ;-) Wir können also eine Selbsthilfegruppe für blinde Programmierer aufmachen. :D

Hier habe ich noch eine Version.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var carpos : Integer;
    replacement, temp : String;
begin
  carpos := Memo1.SelStart;
  case key of
    'ö': replacement := 'oe';
  else
    replacement := '';
  end;

  if replacement <> '' then
  begin
    key := #0;

    temp := memo1.text;
    Insert(replacement, temp, carpos+1);
    memo1.text := temp;

    Memo1.SelStart := carpos + Length(replacement);
  end;
end;


Ich bin mir nämlich nicht sicher, ob das mit dem CaretPos.Y immer funktioniert. Nämlich dann, wenn der Cursor in die nächste Zeile rutscht!

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".