Home > Back-end >  Doing small program how to encapsulate its function?
Doing small program how to encapsulate its function?

Time:09-19

Begin to contact DELPHI10 just for small programs, should be how to find replacement and open the file, and other functions encapsulated ahhh!!!!!!
The unit Unit1;

Interface

USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls, Vcl. Buttons, Vcl. FileCtrl,
Vcl.Com Ctrls, Vcl. Menus, dxGDIPlusClasses, Vcl. ExtCtrls;

Type
TForm1=class (TForm)
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Edit3: TEdit;
BitBtn3: TBitBtn;
StatusBar1: TStatusBar;
RichEdit1: TRichEdit;
CheckBox1: TCheckBox;
Returns: TBitBtn;
Image1: TImage;
Label2: TLabel;
Selected to open the file: TBitBtn;
BitBtn5: TBitBtn;
ReplaceDialog1: TReplaceDialog;
Procedure BitBtn2Click (Sender: TObject);
Procedure DirectoryListBox1MouseUp (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Procedure BitBtn1Click (Sender: TObject);
Procedure BitBtn3Click (Sender: TObject);
Procedure FormCreate (Sender: TObject);
Procedure FormKeyDown (Sender: TObject; Var Key Word; Shift: TShiftState);
Procedure RichEdit1Click (Sender: TObject);
Procedure to return the Click (Sender: TObject);
Procedure FormMouseWheel (Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; Var Handled: Boolean);
Procedure selected to open the file Click (Sender: TObject);
Procedure BitBtn5Click (Sender: TObject);
Procedure ReplaceDialog1Replace (Sender: TObject);
Procedure ReplaceDialog1Find (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;
S, b: string;
A, c: integer;
Implementation
{$R *. DFM}



The function searchfile (path: string) : TStringList;
Var SearchRec: TSearchRec;
Found: integer;//define functions searchfile, find the suffix called pas files
The list: TStringList;
The begin
List:=TStringList. Create;
Found:=FindFirst (path + '\ *. Pas', faAnyFile, SearchRec);
While the found=0 do
The begin
If (SearchRec. Name<> '. ')
And (SearchRec. Name<> '.. ')
And (SearchRec. Attr<> FaDirectory)
Then the List. The Add (SearchRec. Name);
Found:=FindNext (SearchRec);
end;
FindClose (SearchRec);
Searchfile:=list;
end;


Procedure TForm1. BitBtn1Click (Sender: TObject);
The begin
RichEdit1. Lines. The Clear;//to add one layer below the selected folder richedit1 pas file..
RichEdit1. Lines. AddStrings (SearchFile (DirectoryListBox1 GetItemPath (DirectoryListBox1. ItemIndex)));
end;//DirectoryListBox1 GetItemPath (DirectoryListBox1 ItemIndex) for the selected folder path


Procedure TForm1. BitBtn2Click (Sender: TObject);
The begin
If MessageBox (handle, 'sure you want to shut down the program', 'close the window, MB_OKCANCEL)=IDOK//in order to determine if button, retreat to
Then close;//close the program
end;


Procedure TForm1. BitBtn3Click (Sender: TObject);
Var I, j: integer;
S1, s2: string;
The begin
//determine whether case-sensitive
If checkbox1. Checked=true then
The begin
RichEdit1. Lines. LoadFromFile (DirectoryListBox1 GetItemPath (DirectoryListBox1. ItemIndex) + '\' + b);
RichEdit1. Text:=AnsiLowerCase (RichEdit1. Text);
ReplaceDialog1. FindText:=AnsiLowerCase (ReplaceDialog1 findText);
end;
If checkbox1. Checked=false then RichEdit1. Lines. The LoadFromFile (DirectoryListBox1. GetItemPath (DirectoryListBox1. ItemIndex) + '\' + b);
//interception string and record number
i:=0;
S1:=ReplaceDialog1. FindText;
S2:=RichEdit1. Text;
While pos (s1, s2) & gt; 0 do
The begin
S2:=copy (s2, pos (s1, s2) + 1, length (RichEdit1. Text));
Inc (I);
end;
Edit3. Text:=inttostr (I);
If I=0 then showmessage (' can't find your search words!!!! ');
end;


Procedure TForm1. BitBtn5Click (Sender: TObject);
The begin
ReplaceDialog1. Execute;//start replacing
end;



Procedure TForm1. Open the file selected Click (Sender: TObject);
The begin
B:=richedit1. Lines. Strings [a];
If aRichEdit1. Lines. LoadFromFile (DirectoryListBox1 GetItemPath (DirectoryListBox1. ItemIndex) + '\' + RichEdit1. Lines. The Strings [a]);//of the selected file to import into the richedit1
end;

Procedure TForm1. Return to Click (Sender: TObject);
The begin
RichEdit1. Lines. The Clear;//to add one layer below the selected folder memo1 pas file..
RichEdit1. Lines. AddStrings (SearchFile (DirectoryListBox1 GetItemPath (DirectoryListBox1. ItemIndex)));
end;

Procedure TForm1. DirectoryListBox1MouseUp (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin//get the path of the selected DirectoryListBox1
DirectoryListBox1. GetItemPath (DirectoryListBox1. ItemIndex);
end;


Procedure TForm1. FormCreate (Sender: TObject);
Begin/start/forms, empty data
RichEdit1. The Clear;
Edit3. Text:=inttostr (0);
end;


Procedure TForm1. FormKeyDown (Sender: TObject; Var Key Word;
Shift: TShiftState);
The begin F3//buttons, running orientation (Sender) code search words/down (string)
If the key=VK_F3 then ReplaceDialog1Find (Sender);
end;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related