3.2.5.2 方法实现
看一下类中的方法,好象很熟悉,比在Commands单元中定义的方法多出几个。所有的方法已经有具体的实现了。
Destructor TDemoTextWindow.Destroy;
Begin
Inherited Destroy;
//继承父类析构。
End;
{....................................................................................}
{注意:可以在此函数中编写代码来实现把一个文档的内容加载到此文档窗体中,要加载的文件名称使用函数GetState_DocumentName来检索,GetState_DocumentName在TServerWindow类中定义,此函数应在Fileload方法被调用前设置。如果函数被调用成功返回值为True。}
Function TDemoTextWindow.FileLoad : Boolean;
Begin
If FileExists(DocumentName) Then
//如果文件存在,把其加载到控制Memo中。DocumentName是TServerWindow类的属性,存储此文档的文件名称。
Begin
//加载文件。
Memo.Lines.LoadFromFile(DocumentName);
FileLoad := True;//加载成功,返回True。
End
Else
Begin
FileLoad := False;
//不能加载,返回False。
End;
End;
{....................................................................................}
{注意:可以在此函数中编写代码来实现窗体中文件的内容。要保存的文件名称能使用函数GetState_DocumentName来检索,GetState_DocumentName在TServerWindow类中定义,此函数应在FileSave方法被调用前设置。}
Function TDemoTextWindow.FileSave(Format : String) : Boolean;
Begin
Memo.Lines.SaveToFile(DocumentName);//把控制Memo中内容保存到文件中。
FileSave := True;
End;
{....................................................................................}
{注意:在此函数中您将返回一个与此窗体类型相关的面板的窗体句柄}
Function TDemoTextWindow.ReturnPanelHandle : HWnd;
Begin
ReturnPanelHandle := GetState_DemoTextPanelHandle;
//GetState_DemoTextPanelHandle返回TDemoTextPanel类的实例的句柄。
End;
{....................................................................................}
Function TDemoTextWindow.GetState_ChildWindowCount : Integer;
Begin
GetState_ChildWindowCount := 0;
//得到子窗体总数。
End;
{....................................................................................}
{注意:返回此文档的第n个的子文档名称。}
Function TDemoTextWindow.GetState_ChildWindowName(Index : Integer) : String;
Begin
GetState_ChildWindowName := '';
End;
{....................................................................................}
{注意:在editor和frame窗体已被创建但还没有连接到一起后调用,可以在此过程中编写一些代码,来实现初始化文档结构的功能。}
Procedure TDemoTextWindow.PrepareForDrawing;
Begin
//没有实现,只是定义了过程的名称。
End;
{....................................................................................}
{注意:在编辑器editor获得焦点后调用,可编写代码来更新面板panel。}
Procedure TDemoTextWindow.UpdateEnvironment;
Begin
SetState_DemoTextPanelCurrentWindow(Self);
//SetState_DemoTextPanelCurrentWindow定义在Panel1单元中。此过程把当前窗体的父窗体设置为DemoTextPanel.CurrentWindow。
End;
{....................................................................................}
{注意:调用ServerModule方法来抑制或激活特定的命令。}
{例子:MessageRouter_SetState_MenuGray('TextEdit:TextEditorDoUndo',MenuHandle)}
{ MessageRouter_SetState_MenuUnGray ('TextEdit:TextEditorDoUndo',MenuHandle);}
{ MessageRouter_SetState_MenuCheck('TextEdit:TextEditorDoUndo',MenuHandle);}
{MessageRouter_SetState_MenuUnCheck('TextEdit:TextEditorDoUndo',MenuHandle); }
{....................................................................................}
Function TDemoTextWindow.EnableOrDisableMenuItems(MenuHandle : HMenu) : Boolean;
Begin
EnableOrDisableMenuItems := True;
End;
{....................................................................................}
Function TDemoTextWindow.PerformAutoZoom : Boolean;
Begin
PerformAutoZoom := False;
//自动缩放。
End;
{....................................................................................}
Procedure TDemoTextWindow.Clear(Parameters : PChar);
Begin
Memo.ClearSelection;//清除Memo中文本内容。
End;
{....................................................................................}
Procedure TDemoTextWindow.Copy(Parameters : PChar);
Begin
Memo.CopyToClipBoard;//Memo中文本内容复制到粘贴板。
End;
{....................................................................................}
Procedure TDemoTextWindow.CrossProbeChoose(Parameters : PChar);
Begin
SetState_Parameter(Parameters, 'Kind','Text');
SetState_Parameter(Parameters, 'Id', Memo.SelText);
//设置参数,Kind为Text,Id为在Memo中选择的文字。
End;
{....................................................................................}
Procedure TDemoTextWindow.CrossProbeNotify(Parameters : PChar);
Var
Kind: String;
Id: String;
Handle: String;
FocusWindow : String;
Begin
Kind:= 'Unknown';
Id:= 'Unknown';
Handle:= 'Unknown';
FocusWindow := 'Unknown';
//设置为未知类型。
If GetState_Parameter(Parameters, 'Kind' , Kind) Then Kind := UpperCase(Kind);
If GetState_Parameter(Parameters, 'Id' , Id) Then Id := UpperCase(Id);
If GetState_Parameter(Parameters,'Handle',Handle) Then Handle:= UpperCase(Handle);
If GetState_Parameter(Parameters,'FocusWindows',FocusWindow) Then FocusWindow := UpperCase(FocusWindow);
//如果参数中已明确设置,则把参数读出来转换成大写,并放置到相应字符串中。
Memo.Lines.Add('Kind:'+Kind);
Memo.Lines.Add('Id:'+Id);
Memo.Lines.Add('Handle:'+Handle);
Memo.Lines.Add('FocusWindows:'+FocusWindow);
//把参数增加到Memo中。
End;
{....................................................................................}
Procedure TDemoTextWindow.Cut(Parameters : PChar);
Begin
Memo.CutToClipBoard; //Memo中文本内容剪切到粘贴板。
End;
{....................................................................................}
Procedure TDemoTextWindow.Paste(Parameters : PChar);
Begin
Memo.PasteFromClipBoard; //从粘贴板中把内容粘贴过来。
End;
{....................................................................................}
//把Memo中内容输出到打印机。
Procedure TDemoTextWindow.PrintDocument(Parameters : PChar);
Var
F : TextFile;
i : LongInt;
Begin
If PrintDialog.Execute Then
Begin
AssignPrn(F);
Rewrite(F);
Printer.Canvas.Font := Memo.Font;
For i := 0 to Memo.Lines.Count-1 Do
WriteLn(F,Memo.Lines.Strings[i]);
CloseFile(F);
End;
End;
{....................................................................................}
Procedure TDemoTextWindow.Redo(Parameters : PChar);
Begin
Inherited Redo(Parameters);//redo功能。
ShowInfo('Redo没有实现');
End;
{....................................................................................}
//设置Memo控件中的字体。
Procedure TDemoTextWindow.SetupPreferences(Parameters : PChar);