반응형
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TRichEdit = class(ComCtrls.TRichEdit) //ComCtrls의 RichEdit를 상속
Public
procedure AddLast(S: string);
end;
TForm1 = class(TForm)
RichEdit1: TRichEdit; //ComCtrls에서 정의한 RichEdit가 아니고 위에서 정의한 RichEdit가 되겠습니다.
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TRichEdit }
procedure TRichEdit.AddLast(S: string); //문장 추가 부분
var
SelStart: Integer;
begin
if Lines.Count < 1 then
SetWindowText(Handle, PChar(S))
else
begin
SelStart := SendMessage(Handle, EM_LINEINDEX, Lines.Count, 0);
SendMessage(Handle, EM_SETSEL, SelStart, SelStart);
SendMessage(Handle, EM_REPLACESEL, 0, Longint(PChar(#13+#10+S)));
end;
Perform(WM_VSCROLL, SB_BOTTOM, 0); // 맨 마지막으로 스크롤
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.AddLast('마지막에 문자을 입력합니다!');
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TRichEdit = class(ComCtrls.TRichEdit) //ComCtrls의 RichEdit를 상속
Public
procedure AddLast(S: string);
end;
TForm1 = class(TForm)
RichEdit1: TRichEdit; //ComCtrls에서 정의한 RichEdit가 아니고 위에서 정의한 RichEdit가 되겠습니다.
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TRichEdit }
procedure TRichEdit.AddLast(S: string); //문장 추가 부분
var
SelStart: Integer;
begin
if Lines.Count < 1 then
SetWindowText(Handle, PChar(S))
else
begin
SelStart := SendMessage(Handle, EM_LINEINDEX, Lines.Count, 0);
SendMessage(Handle, EM_SETSEL, SelStart, SelStart);
SendMessage(Handle, EM_REPLACESEL, 0, Longint(PChar(#13+#10+S)));
end;
Perform(WM_VSCROLL, SB_BOTTOM, 0); // 맨 마지막으로 스크롤
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.AddLast('마지막에 문자을 입력합니다!');
end;
end.
반응형