📄 unit1.pas
字号:
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RzCmboBx, ExtCtrls;
Type
TForm1 = Class(TForm)
edtProperty: TEdit;
mmoCode: TMemo;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
Label3: TLabel;
cbxPropertyType: TRzComboBox;
cbPublish: TCheckBox;
Label4: TLabel;
Label5: TLabel;
edtDefaultValue: TEdit;
Label6: TLabel;
edtClassName: TEdit;
Bevel1: TBevel;
Button3: TButton;
Button4: TButton;
cbxIncludeComment: TCheckBox;
Procedure Button2Click(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure Button3Click(Sender: TObject);
Procedure Button4Click(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
Procedure AddABlankLine;
End;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
{
FShowNumber: boolean;
Procedure setLongItemHeight(Value: integer);
Property MarkCurrentPOS: boolean Read FmarkCurrentPos Write SetMarkCurrentPOS;
Procedure TLevonRuler.setLongItemHeight(Value: integer);
Begin
If FlongItemHeight <> Value Then
FlongItemHeight := Value;
invalidate;
End;
Constructor Create(AOwner: TComponent); Override;
Constructor TLevonRuler.Create(AOwner: TComponent);
Begin
FlongItemHeight := 20;
FShortItemHeight := 10;
Inherited;
End;
}
Procedure TForm1.Button2Click(Sender: TObject);
Begin
edtProperty.Clear;
cbxPropertyType.ItemIndex := 0;
cbPublish.Checked := true;
mmoCode.Lines.Clear;
edtDefaultValue.Clear;
edtProperty.SetFocus;
End;
Procedure TForm1.AddABlankLine;
Begin
mmoCode.Lines.Add('');
End;
Procedure TForm1.Button1Click(Sender: TObject);
Const
PropertyPerfix = 'F';
ProcedurePerfix = 'Set';
Var
ProperyName: String;
ProcedureName: String;
Begin
//属性名称;
If edtProperty.Text = '' Then
Exit;
//属性类型;
If cbxPropertyType.Text = '' Then
Exit;
ProperyName := PropertyPerfix + edtProperty.Text;
ProcedureName := ProcedurePerfix + edtProperty.Text;
mmoCode.Lines.Clear;
//1..private 生成声明;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//Private 部分');
mmoCode.Lines.Add(ProperyName + ':' + cbxPropertyType.Text + ';');
AddABlankLine;
//2..
mmoCode.Lines.Add('Procedure ' + ProcedureName + '(Value:' + cbxPropertyType.Text + ');');
AddABlankLine;
//3.生成publish的东西;
If cbPublish.Checked Then
Begin
// Property MarkCurrentPOS: boolean Read FmarkCurrentPos Write SetMarkCurrentPOS;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//Publish 部分');
mmoCode.Lines.Add('Property ' + edtProperty.Text + ':' + cbxPropertyType.Text + ' Read ' + ProperyName + ' Write ' + ProcedureName + ';');
AddABlankLine;
End;
//下面是implementation 的实现;
{Procedure TLevonRuler.setLongItemHeight(Value: integer);
Begin
If FlongItemHeight <> Value Then
FlongItemHeight := Value;
invalidate;
End;}
//2..可以在oncreate中生成默认值;
//4..组件的oncreate 事件中;
//下面这个是procedure 的实现;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//下面添加到OnCreate 过程中');
mmoCode.Lines.Add(ProperyName + ':=' + edtDefaultValue.Text + ';');
AddABlankLine;
//下面这个是procedure 的实现;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//Implementation 部分');
mmoCode.Lines.Add('Procedure ' + edtClassName.Text + '.' + ProcedureName + '(Value:' + cbxPropertyType.Text + ');');
mmoCode.Lines.Add('Begin');
mmoCode.Lines.Add(' If ' + ProperyName + '<>Value Then');
mmoCode.Lines.Add(' ' + ProperyName + ':=Value;');
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add(' //如果需要刷新,代码写在这里;');
mmoCode.Lines.Add('End;');
AddABlankLine;
End;
Procedure TForm1.Button3Click(Sender: TObject);
Begin
mmoCode.SelectAll;
mmoCode.CopyToClipboard;
ShowMessage('代码已经拷贝到剪贴板');
End;
Procedure TForm1.Button4Click(Sender: TObject);
Begin
mmoCode.Lines.Clear;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//这句写在public 部分;');
mmoCode.Lines.Add('Constructor Create(AOwner: TComponent); Override;');
mmoCode.Lines.Add('Destructor Destroy; Override;');
AddABlankLine;
AddABlankLine;
//oncreate;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//OnCreate 这段写在Implentation部分;');
mmoCode.Lines.Add('Constructor ' + edtClassName.Text + '.Create(AOwner: TComponent);');
mmoCode.Lines.Add('Begin');
mmoCode.Lines.Add(' inherited Create(AOwner);' + ' //继承...');
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add(' //属性赋默认值,或初始化代码写在这里...');
AddABlankLine;
mmoCode.Lines.Add('End;');
AddABlankLine;
AddABlankLine;
//ondestroy;
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add('//OnDestroy 这段写在Implentation部分;');
mmoCode.Lines.Add('Destructor ' + edtClassName.Text + '.Destroy;');
mmoCode.Lines.Add('Begin');
If cbxIncludeComment.Checked Then
mmoCode.Lines.Add(' //将释放代码写在这里...');
AddABlankLine;
mmoCode.Lines.Add(' inherited Destroy;' + ' //继承...');
mmoCode.Lines.Add('End;');
End;
End.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -