const
txt = 'Seriennummer:'; // fester Text
lt = length(txt) + 1;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.text := txt + #32;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
c: char;
lg, diff: integer;
begin
if key = #8 then begin
if edit1.selstart <= lt then begin
lg := edit1.sellength;
diff := lt - edit1.selstart;
if (lg > 0) and (edit1.selstart + edit1.sellength > lt) then begin
edit1.selstart := lt;
edit1.sellength := lg - diff;
end else begin
key := #0;
edit1.selstart := length(edit1.text);
end;
end;
end else begin
c := key;
key := #0;
edit1.text := txt + #32 + trim(stringreplace(edit1.text, txt, '', [rfreplaceall])) + c;
edit1.selstart := length(edit1.text);
end;
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var lg, diff: integer;
begin
if key = 46 then begin
if edit1.selstart < lt then begin
lg := edit1.sellength;
diff := lt - edit1.selstart;
if (lg > 0) and (edit1.selstart + edit1.sellength > lt) then begin
edit1.selstart := lt;
edit1.sellength := lg - diff;
end else begin
key := 0;
edit1.selstart := lt;
end;
end;
end;
end;