📄 smscommreg.pas
字号:
unit SMSCommReg;
interface
{$I SMSComm.inc}
{.$R SMSCommReg.dcr}
uses
{$IFDEF DELPHI_6_OR_HIGHER}
DesignIntf, DesignEditors, DesignMenus, PropertyCategories,
{$ELSE}
DsgnIntf,
{$ENDIF}
Windows, Classes;
type
{$IFDEF DELPHI_6_OR_HIGHER}
TGetPropEditProc = procedure(const Prop: IProperty) of object;
{$ENDIF}
{ TSMSCommComponentEditor }
TSMSCommComponentEditor = class(TComponentEditor)
protected
procedure CallPropertyEditor(Proc: TGetPropEditProc);
{$IFDEF DELPHI_6_OR_HIGHER}
procedure CommandHandlersEditor(const Prop: IProperty);
{$ELSE}
procedure CommandHandlersEditor(Prop: TPropertyEditor);
{$ENDIF}
public
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
procedure Edit; override;
end;
// TComPort.Port property editor
TComPortProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
end;
{ TAboutPropertyEditor }
TAboutPropertyEditor = class(TStringProperty)
public
procedure Edit; override;
function GetValue: string; override;
function GetAttributes: TPropertyAttributes; override;
end;
procedure Register;
//----------------------------------------------------------------------------------------------------------------------
implementation
uses
SMSComm, TypInfo, Dialogs;
procedure ShowAboutBox(const ClassName: String);
const
AboutStr = ' v3.00' + #13#10
+ 'Copyright(C) 1999-2006 黄晓斌' + #13#10
+ 'All rights reserved. 国防科技大学' + #13#10
+ #13#10
+ 'hxbtougao@yahoo.com.cn';
begin
MessageDlg(ClassName + AboutStr, mtInformation, [mbOK], 0);
end;
(*****************************************
* TSMSCommComponentEditor editor *
*****************************************)
function TSMSCommComponentEditor.GetVerbCount: Integer;
begin
Result := 3;
end;
function TSMSCommComponentEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result := 'About ' + Component.ClassName + '...';
1: Result := '-';
2: Result := 'CommandHandlers Editor...';
else
Result := '';
end;
end;
procedure TSMSCommComponentEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0: ShowAboutBox(Component.ClassName);
1: {Nothing to do};
2: CallPropertyEditor(CommandHandlersEditor);
else
inherited ExecuteVerb(Index);
end;
end;
procedure TSMSCommComponentEditor.Edit;
begin
ExecuteVerb(2);
end;
procedure TSMSCommComponentEditor.CallPropertyEditor(Proc: TGetPropEditProc);
var
{$IFDEF DELPHI_6_OR_HIGHER}
List: IDesignerSelections;
{$ELSE}
{$IFDEF DELPHI_5_OR_HIGHER}
List: TDesignerSelectionList;
{$ELSE}
List: TComponentList;
{$ENDIF}
{$ENDIF}
begin
{$IFDEF DELPHI_6_OR_HIGHER}
List := TDesignerSelections.Create;
{$ELSE}
{$IFDEF DELPHI_5_OR_HIGHER}
List := TDesignerSelectionList.Create;
{$ELSE}
List := TComponentList.Create;
{$ENDIF}
{$ENDIF}
try
List.Add(Component);
GetComponentProperties(List, [tkClass], Designer, Proc);
finally
{$IFNDEF DELPHI_6_OR_HIGHER}
List.Free;
{$ENDIF}
end;
end;
{$IFDEF DELPHI_6_OR_HIGHER}
procedure TSMSCommComponentEditor.CommandHandlersEditor(const Prop: IProperty);
{$ELSE}
procedure TSMSCommComponentEditor.CommandHandlersEditor(Prop: TPropertyEditor);
{$ENDIF}
begin
if Prop.GetName = 'CommandHandlers' then
Prop.Edit;
end;
(*****************************************
* TComPortProperty editor *
*****************************************)
function TComPortProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paRevertable, paSortList, paValueList];
end;
procedure TComPortProperty.GetValues(Proc: TGetStrProc);
var
List: TStringList;
I: Integer;
begin
List := TStringList.Create;
EnumComPorts(List);
for I := 0 to List.Count - 1 do
Proc(List[I]);
List.Free;
end;
(*****************************************
* TAboutPropertyEditor editor *
*****************************************)
function TAboutPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paReadOnly, paMultiSelect];
end;
function TAboutPropertyEditor.GetValue: string;
begin
Result := '(About)'
end;
procedure TAboutPropertyEditor.Edit;
begin
ShowAboutBox(GetComponent(0).ClassName);
end;
procedure Register;
begin
RegisterComponents('SMSComm', [TSMSComm]);
RegisterComponentEditor(TSMSComm, TSMSCommComponentEditor);
RegisterPropertyEditor(TypeInfo(TPort), TComPort, 'Port', TComPortProperty);
RegisterPropertyEditor(TypeInfo(TAbout), TSMSComm, 'About', TAboutPropertyEditor);
end;
//----------------------------------------------------------------------------------------------------------------------
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -