📄 unewcomp.pas
字号:
unit UNewcomp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TNewComponent = class(TForm)
Label2: TLabel;
Label1: TLabel;
Label3: TLabel;
Label5: TLabel;
Label4: TLabel;
ClassList: TComboBox;
NewClassName: TEdit;
PageNames: TComboBox;
EditFileName: TEdit;
BrowseButton: TButton;
EditSearchPath: TEdit;
UnitNameDialog: TSaveDialog;
Bevel1: TBevel;
Button1: TButton;
Button2: TButton;
btnCreate: TButton;
btnInstall: TButton;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BrowseButtonClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ClassListClick(Sender: TObject);
procedure btnCreateClick(Sender: TObject);
private
{ Private declarations }
ComponentList:TStringList;
public
{ Public declarations }
end;
var
NewComponent: TNewComponent;
implementation
uses Uconst, utils, Editor;
{$R *.DFM}
function CreateNewComponentCode(const Ancestor,NewClassName,Page,UnitName:string):string;
var
List:TStringList;
begin
List:=TStringList.Create;
with List do begin
Add(Format('%s %s;',['unit',UnitName]));
Add(' ');
Add('interface');
Add(' ');
Add('uses');
Add(' Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;');
Add(' ');
Add('type');
Add(Format(' %s=class(%s)',[NewClassName, Ancestor]));
Add(' private');
Add(' { Private declarations }');
Add(' public');
Add(' { Public declarations }');
Add(' end;');
Add(' ');
Add('procedure Register');
Add(' ');
Add('implementation');
Add(' ');
Add('procedure Register;');
Add('begin');
Add(Format(' RegisterComponents(%s,[%s]);',[Page, ClassName]));
Add('end');
Add(' ');
Add('end.');
end;
Result:=List.Text;
List:= nil;
List.Free;
end;
procedure TNewComponent.FormShow(Sender: TObject);
// Get palette pages list
begin
PageNames.Items.Text:= GetPalettePage;
ComponentList.Text:= GetAllComponentList;
ClassList.Items:= ComponentList;
PageNames.ItemIndex:= 0;
end;
procedure TNewComponent.FormCreate(Sender: TObject);
begin
ComponentList:= TStringList.Create;
end;
procedure TNewComponent.FormDestroy(Sender: TObject);
begin
ComponentList.Free;
end;
procedure TNewComponent.BrowseButtonClick(Sender: TObject);
begin
if UnitNameDialog.Execute then
EditFileName.Text:= UnitNameDialog.FileName;
end;
procedure TNewComponent.Button1Click(Sender: TObject);
var
KeyWord:string;
begin
KeyWord:= 'New Component command';
Application.HelpCommand(HELP_KEY,longint(KeyWord));
end;
procedure TNewComponent.ClassListClick(Sender: TObject);
var
UnitName:string;
begin
UnitName:= Copy(ClassList.Text, 2 , 255);
NewClassName.Text:= Format('%s%d',[ClassList.Text, 1]);
EditFileName.Text:= Format('%s%s%s.pas',[FilePath,UnitName, '1']);
// btnInstall.Enabled:= True;
btnCreate.Enabled:= True;
end;
procedure TNewComponent.btnCreateClick(Sender: TObject);
var
Code,UnitName:string;
begin
EditorForm.NewSheet(EditFileName.Text);
UnitName:= GetNetFileName(EditFileName.Text);
Code:= CreateNewComponentCode(ClassList.Text, NewClassName.Text, PageNames.Text,UnitName);
ActivePasEditor.Lines.Text:= Code;
ModalResult:= mrOK;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -