Hi,
ich habe auch mal sowas aehndliches geschrieben wie den Delphi-Editor zu Testzwecken.
Hier der Quellcode:
Delphi-Quellcode:
private
{ Private declarations }
CodeList : TListBox;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CodeListClick(Sender: TObject);
Var
CurLine : Integer;
begin
if CodeList.ItemIndex <> -1 then
begin
CurLine := Editor.CaretPos.Y;
Editor.Lines[CurLine] := Editor.Lines[CurLine] + CodeList.Items[CodeList.ItemIndex];
end;
CodeList.Visible := False;
Editor.SetFocus;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CodeList := TListBox.Create(Self);
CodeList.Parent := Editor;
CodeList.Visible := False;
CodeList.Width := 200;
CodeList.Height := 100;
CodeList.Items.Add('Caption');
CodeList.Items.Add('Top');
CodeList.Items.Add('Left');
CodeList.OnClick := CodeListClick;
CodeList.OnKeyDown := CodeListKeyDown;
end;
procedure TForm1.CodeListKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Var
CurLine : Integer;
begin
case Key of
13 : begin
if CodeList.ItemIndex <> -1 then
begin
CurLine := Editor.CaretPos.Y;
Editor.Lines[CurLine] := Editor.Lines[CurLine] + CodeList.Items[CodeList.ItemIndex];
end;
end;
end;
CodeList.Visible := False;
Editor.SetFocus;
end;
procedure TForm1.EditorKeyPress(Sender: TObject; var Key: Char);
Var
CliPos : TPoint;
ListX, ListY : Integer;
begin
if Key = '.' then
begin
GetCaretPos(CliPos);
ListX := CliPos.X;
ListY := CliPos.Y + CodeList.Canvas.TextHeight('W') + 4;
if ListX + CodeList.Width >= Editor.Width then
ListX := Editor.Width - CodeList.Width - 20;
if ListY + CodeList.Height >= Editor.Height then
ListY := Editor.Height - CodeList.Height - 20;
with CodeList do
Begin
Top := ListY;
Left := ListX;
ItemIndex := 0;
Visible := True;
SetFocus;
end;
end
else
CodeList.Visible := False;
end;
end.
Um etwas Neues zu schaffen muss man seine Ohren vor den Nein-sagern verschliessen um seinen Geist öffnen zu können.
(George Lukas)