Autor Beitrag
J.Borchert
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 150

WIN10
XE2 Professional
BeitragVerfasst: Mo 25.12.06 09:53 
Also wie mache ich das. Muß ich wirklich jeden Tastendruck abfangen, selLenght wenn richtige Taste gedrückt wird auf eins stellen und dann selText ersetzen ?

Oder geht's einfacher?

mfG Juergen
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 25.12.06 11:06 
Hallo,

wenn es in Deine Anwendung passt, nimm ein RichEdit, denn da ist es schon eingebaut.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
J.Borchert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 150

WIN10
XE2 Professional
BeitragVerfasst: Mo 25.12.06 13:01 
Das mit dem RichEdit mag stimmen. Wollte aber nunmal mit Memo vorwärtskommen.
Habe hier mal die Lösung:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
uses windows {...} ;
// ...
public  { Public-Deklarationen }
   procedure MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
   // beim Erstellen jeden Memos wird Memo.OnKeyDown:=MemoKeyDown; zugeordnet
end;
{...}
procedure TForm1.MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var m:TMemo; s:string; c:integer;
begin m:=TMemo(Form1.FindComponent('MPC'+IntToStr(PageControl1.ActivePageIndex+1)));
      if m = nil then exit; 
      // habe mehrere Memos zur Laufzeit erstellt und checke, welches aktiv ist
      
      if key = vk_insert then // Wechseln zwischen Überschreiben und Einfügen
       begin if m.Tag=0 then m.Tag:=1 else m.Tag:=0;
             if m.Tag=1 then Form1.StatusBar1.Panels.Items[4].Text:='Overwrite';
             if m.Tag=0 then Form1.StatusBar1.Panels.Items[4].Text:='Insert';
             exit;
       end;
      // Es werden nur Buchstaben und Zahlen überschrieben
      if ( Key >= ord('0') ) and // Taste Zahlen beginnt bei key=48
         ( key <= ord('z') ) and // Taste Buchstaben endet bei key=122
         ( m.Tag = 1 ) then // Am Memo.Tag wird der Modus erkannt
         ( m.SelLength = 0 ) and // Nur wenn nichts im Memo markiert ist
         ( m.SelStart < length(m.Text) ) and // Nicht am Ende des Memos
         ( Shift = [] ) then // Keine Sondertastenkombination
          begin s:=m.Text; // s weil delete nicht mit const m.Text arbeitet
                c:=m.SelStart; // Cursorposition sichern
                delete(s,m.SelStart+1,1); // folgendes Zeichen löschen
                m.Text:=s; m.SelStart:=c; // m.Text verändern, Cursor setzen
          end;
end;

Hoffe alle "Neuen" haben so auch was davon :lol:

Frohes Fest und guten Rutsch sagt Jürgen
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 27.12.06 00:48 
Hallo,

in Zeile 23 hat sich der Kopier-Fehlerteufel in Deinen Code eingeschlichen :wink:, oder?

Mit FindComponent kann ich mich nicht so recht anfreunden,
zumal Sender das entsprechende Memo liefert.

Hier mal meine Variante:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
//...
var
  Form1: TForm1;
const
  INS : array [0..1of String = ('Insert''Overwrite');

implementation

{$R *.DFM}
procedure TForm1.MyMemoEnter(Sender: TObject);
begin
  with TEdit(Sender) do
    StatusBar1.Panels.Items[0].Text := INS[Tag];
end;

procedure TForm1.MyMemoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  with TEdit(Sender) do
    if Key = VK_INSERT then // Wechseln zwischen Überschreiben und Einfügen
      begin
      Tag := Tag xor 1;
      StatusBar1.Panels.Items[0].Text := INS[Tag];
      end;
end;

procedure TForm1.MyMemoKeyPress(Sender: TObject; var Key: Char);
begin
  with TEdit(Sender) do
    if Tag = 1 then
      if SelLength = 0 then
        if Key in [#32..#126,#128..#255then
          begin
          SelLength := 1;
          if (SelLength > 0and (SelText[1] = #13then
            SelLength := 0;//Zeilenumbrüche nicht überschreiben = Standard
            //SelLength := 2;//alternativ auch Zeilenumbrüche überschreiben
          end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )