·ReturnIconsAndBitmaps
{注意:覆盖默认的图标和位图,如果您不这样做,TServerModule将给客户端提供默认的图标和位图。}
//返回图标和位图。
Procedure TDemoTextServerModule.ReturnIconsAndBitmaps(WindowKind: String;
Var StandardBitmap: HBitmap;
Var TopLevelBitmap: HBitmap;
Var MainInstanceBitmap : HBitmap;
Var DocumentIcon: HIcon);
Begin
If WindowKind = 'DEMOTEXT' Then
Begin
StandardBitmap:= DefaultStandardBitMap;
TopLevelBitmap:= DefaultTopLevelBitmap;
MainInstanceBitmap := DefaultMainInstanceBitmap;
DocumentIcon:= DefaultDocumentIcon;
End;
End;
DefaultStandardBitMap、DefaultTopLevelBitmap、DefaultMainInstanceBitmap、DefaultDocumentIcon是在TServerModule类中定义的表示图标对象。
ReturnIconsAndBitmaps过程为“DEMOTEXT”服务器设置图标和位图。
3.2.2增加进程到命令表
在TDemoTextServerModule类的CreateServer方法中,调用了LoadCommandLauncherTable过程。LoadCommandLauncherTable过程定义在单元ComTable中,过程增加了多个进程到命令表中,代码实现如下:
Procedure LoadCommandLauncherTable;
Begin
CreateCommandLauncherTable;
CommandLauncherTable_State_AddCommand('Clear', @Command_Clear);
CommandLauncherTable_State_AddCommand('Copy',@Command_Copy);
CommandLauncherTable_State_AddCommand('CrossProbeChoose', @Command_CrossProbeChoose);
CommandLauncherTable_State_AddCommand('CrossProbeNotify', @Command_CrossProbeNotify);
CommandLauncherTable_State_AddCommand('Cut', @Command_Cut);
CommandLauncherTable_State_AddCommand('Paste', @Command_Paste);
CommandLauncherTable_State_AddCommand('PrintDocument', @Command_PrintDocument);
CommandLauncherTable_State_AddCommand('Redo', @Command_Redo);
CommandLauncherTable_State_AddCommand('SetupPreferences', @Command_SetupPreferences);
CommandLauncherTable_State_AddCommand('SetupPrinter', @Command_SetupPrinter);
CommandLauncherTable_State_AddCommand('Undo', @Command_Undo);
SortCommandLauncherTable;
End;
此服务器定义了很多进程,如Copy、Paste、Cut等等,这个命令可以在客户端调用,如同在客户端调用原理图编辑器或印制板编辑器命令一样。
3.2.3 Commands单元
服务器提供的进程如Clear、Copy、Paste、Cut等都实现在Commands单元中,我们打开Commands单元,看一看如果实现,但是很奇怪,此单元中这样方法都未具体实现,如Clear方法:
Procedure Command_Clear(Window : TAbstractServerWindow; Parameters : PChar);
Begin
If Window <> Nil Then Window.Clear(Parameters);
End;
但我们能看到有一个参数是TAbstractServerWindow类,此类实例不为空时,执行Clear,说明此类是一个表示编辑器窗体的类,OK,有了此点认识,让我们来找一找此类在何处定义,很容易就能找到,此类在Abstract单元中定义。
3.2.4 Abstract单元
在Abstract单元中,TAbstractServerWindow定义如下:
Type
TAbstractServerWindow = Class(TServerWindow)
Private
Public
Procedure Clear(Parameters : PChar);Virtual;
Procedure Copy(Parameters : PChar);Virtual;
Procedure CrossProbeChoose(Parameters : PChar);Virtual;
Procedure CrossProbeNotify(Parameters : PChar);Virtual;
Procedure Cut(Parameters : PChar);Virtual;
Procedure Paste(Parameters : PChar);Virtual;
Procedure PrintDocument(Parameters : PChar);Virtual;
Procedure Redo(Parameters : PChar); Virtual;
Procedure SetupPreferences(Parameters : PChar);Virtual;
Procedure SetupPrinter(Parameters : PChar);Virtual;
Procedure Undo(Parameters : PChar);Virtual;
End;
//TAbstractServerWindow类是从TServerWindow继承的,在此类中定义的如clear和copy等命令都未具体实现,
//只是显示一个提示说命令没有实现。
让我们看一看,这些方法如Clear是如何实现的?
Procedure TAbstractServerWindow.Clear(Parameters : PChar);
Begin
DisplayNotImplementedMessage('Clear','Delete all selections from the current document');
//DisplayNotImplementedMessage过程显示一个消息框框信息,用户指定的进程依然没有实现,Protel SDK自动代码生成器为所有进程插入此函数。
//参数类型描述
//ProcessIdTString指定进程名称。
//ProcessDescriptionTString为此进程指定一个描述。
End;
比较遗憾,方法还是没有具体实现,那么,方法究竟在何在实现呢?
3.2.5编辑器窗体
让我们回头看一下Main单元中ReturnNewWindow函数,其创建了一个TDemoTextWindow类的实例,此实例看起来象是一个窗体。让我们来找一下TDemoTextWindow类在哪一个单元中定义,是Editor1单元,同时,此单元还定义了一个窗体,如图7-5所示。

图7-5 编辑器窗体
3.2.5.1 TDemoTextWindow类定义
Type
TDemoTextWindow = Class(TCommonWindow)
PrintDialog: TPrintDialog;
PrinterSetupDialog : TPrinterSetupDialog;
Memo: TMemo;
FontDialog: TFontDialog;
procedure MemoChange(Sender: TObject);
procedure FormActivate(Sender: TObject);
Private
Public
DestructorDestroy;OverRide;
ProcedurePrepareForDrawing;OverRide;
FunctionEnableOrDisableMenuItems(MenuHandle : HMenu) : Boolean;OverRide;
FunctionPerformAutoZoom: Boolean;OverRide;
FunctionReturnPanelHandle: HWnd;OverRide;
FunctionFileLoad: Boolean;OverRide;
FunctionFileSave(Format : String) : Boolean;OverRide;
FunctionGetState_ChildWindowCount : Integer;OverRide;
FunctionGetState_ChildWindowName(Index : Integer) : String;OverRide;
ProcedureUpdateEnvironment;OverRide;
ProcedureClear(Parameters : PChar);OverRide;
ProcedureCopy(Parameters : PChar);OverRide;
ProcedureCrossProbeChoose(Parameters : PChar);OverRide;
ProcedureCrossProbeNotify(Parameters : PChar);OverRide;
ProcedureCut(Parameters : PChar);OverRide;
ProcedurePaste(Parameters : PChar);OverRide;
ProcedurePrintDocument(Parameters : PChar);OverRide;
ProcedureRedo(Parameters : PChar);OverRide;
ProcedureSetupPreferences(Parameters : PChar);OverRide;
ProcedureSetupPrinter(Parameters : PChar);OverRide;
ProcedureUndo(Parameters : PChar);OverRide;
End;
//TDemoTextWindow类从TCommonWindow类继承,与父类相比,此类增加了两个过程,MemoChange和FormActivate。另外,此类有一个窗体,其中放置了TPrintDialog组件PrintDialog、TPrinterSetupDialog组件PrinterSetupDialog,TMemo控件Memo和TFontDialog组件FontDialog。组件PrintDialog用于执行弹出打印机对话框功能,组件PrinterSetupDialog用于执行设置打印机,弹出一个打印机设置对话框,组件FontDialog用于设置控件Memo中文字的字体,控件Memo用于编写文字。
//此类把其父类中未实现的过程和函数进行具体实现。