20.10.2011, 11:26
|
|
Гуру
|
|
Регистрация: 09.03.2009
Адрес: На курорте, из окна вижу теплое Баренцево море. Бррр.
Сообщения: 4,721
Репутация: 52347
|
|
Вот так устроит?
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TSpeedButton;
Button3: TSpeedButton;
RichEdit1: TRichEdit;
RichEdit2: TRichEdit;
Button4: TButton;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not OpenDialog1.Execute then Exit;
RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
FoundAt: LongInt;
StartPos: Integer;
begin
if RichEdit1.SelLength <> 0
then StartPos := RichEdit1.SelStart + RichEdit1.SelLength
else StartPos := 0;
FoundAt := RichEdit1.FindText('<body>', StartPos, Length(RichEdit1.Text), [stMatchCase]);
if FoundAt <> -1
then begin
RichEdit1.SetFocus;
RichEdit1.SelStart := FoundAt + Length('<body>');
RichEdit1.SelLength := RichEdit1.FindText('</body>', RichEdit1.SelStart, Length(RichEdit1.Text), [stMatchCase]) - RichEdit1.SelStart;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
RichEdit1.SelText := RichEdit2.Text
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SaveDialog1.FileName := OpenDialog1.FileName;
if not SaveDialog1.Execute then Exit;
RichEdit1.Lines.SaveToFile(SaveDialog1.FileName);
end;
end.
и dfm-файл
Код:
object Form1: TForm1
Left = 350
Top = 114
Width = 870
Height = 640
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
DesignSize = (
862
606)
PixelsPerInch = 96
TextHeight = 13
object Button2: TSpeedButton
Left = 8
Top = 480
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = 'Find'
OnClick = Button2Click
end
object Button3: TSpeedButton
Left = 96
Top = 480
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = 'Replace'
OnClick = Button3Click
end
object Button1: TButton
Left = 8
Top = 8
Width = 75
Height = 25
Caption = 'Load...'
TabOrder = 0
OnClick = Button1Click
end
object RichEdit1: TRichEdit
Left = 8
Top = 40
Width = 849
Height = 433
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssBoth
TabOrder = 1
end
object RichEdit2: TRichEdit
Left = 8
Top = 512
Width = 849
Height = 89
Anchors = [akLeft, akRight, akBottom]
TabOrder = 2
end
object Button4: TButton
Left = 88
Top = 8
Width = 75
Height = 25
Caption = 'Save as...'
TabOrder = 3
OnClick = Button4Click
end
object OpenDialog1: TOpenDialog
Filter = '*.htm|*.htm'
Left = 152
Top = 80
end
object SaveDialog1: TSaveDialog
Filter = '*.htm|*.htm'
Options = [ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]
Left = 232
Top = 80
end
end
__________________
Жизнь такова какова она есть и больше никакова.
Помогаю за спасибо.
|