如何在DELPHI的源码编辑窗口中插入字符?100分小噫嘻。(100分)

  • 主题发起人 主题发起人 Jayant
  • 开始时间 开始时间
Energy的诗歌才华真是让人佩服.
 
在这里聊天,
佩服佩服,
不过我还不知道专家是什么意思,不知道能不能...?
这里先谢过了.

才疏学浅,没脸见人呀.
 
我已经找到插入字符的方法,不过程序还有些乱,代我整理后载贴出来!!!
{B-)
 
程序在设置快捷键有点问题,请赖心等候....
 
{快捷键有点问题,不知试程序原因还是Delphi IDE的错误造成的,希起抛砖引玉的作用!!! {B-)}
library Exptdemo;

uses
ShareMem,
Forms,
Windows,
Menus,
Classes,
ExptIntf,
ToolIntf,
VirtIntf,
EditIntf,
SysUtils;

type
TMyExpert = class(TIExpert)
private
FMyExpert: TIMenuItemIntf;
public
procedure MyExpertClick(Sender: TIMenuItemIntf);
function GetName: string; override;
function GetComment: string; override;
function GetGlyph: HICON; override;
function GetStyle: TExpertStyle; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
function GetAuthor: string; override;
function GetPage: string; override;
function GetMenuText: string; override;
constructor Create;
destructor Destroy; override;
procedure Execute;override;
end;

{$R EXPTBMPS.RES}

procedure HandleException;
begin
ToolServices.RaiseException(ReleaseException);
end;

{ TDialogExpert }
function TMyExpert.GetName: string;
begin
try
Result := 'MyExpert';
except
HandleException;
end;
end;

function TMyExpert.GetComment: string;
begin
try
Result := 'MyExpert, by 沈前卫 shenqw@cmmail.com';
except
HandleException;
Result:='';
end;
end;

function TMyExpert.GetGlyph: HICON;
begin
Result := 0;
end;

function TMyExpert.GetStyle: TExpertStyle;
begin
try
Result := esAddin;
except
HandleException;
Result := esAddin;
end;
end;

function TMyExpert.GetState: TExpertState;
begin
try
Result := [esEnabled,esChecked];
except
HandleException;
Result := [];
end;
end;

function TMyExpert.GetIDString: string;
begin
try
Result := 'Shenqw.MyExpert';
except
HandleException;
Result := '';
end;
end;

function TMyExpert.GetAuthor: string;
begin
try
Result := 'Shenqw';
except
HandleException;
Result := '';
end;
end;

function TMyExpert.GetPage: string;
begin
Result := '';
end;

function TMyExpert.GetMenuText: string;
begin
Result := 'My_Expert';
end;

constructor TMyExpert.Create;
var
MainMenu: TIMainMenuIntf;
MenuItems, HelpBorlandPage, HelpMenu: TIMenuItemIntf;
begin
inherited Create;
MainMenu := ToolServices.GetMainMenu;
if MainMenu <> nil then
try
MenuItems := MainMenu.GetMenuItems;
if MenuItems <> nil then
try
HelpBorlandPage := MainMenu.FindMenuItem('ViewPrjMgrItem');
if HelpBorlandPage <> nil then
try
HelpMenu := HelpBorlandPage.GetParent;
if HelpMenu <> nil then
try
FMyExpert := HelpMenu.InsertItem(0,
'My_Expert','MyExpertMenuItem','This is a test',integer(ShortCut(Ord('k'),[ssCtrl,ssAlt])),0,0,
[mfVisible, mfEnabled], MyExpertClick);
finally
HelpMenu.Free;
end;
finally
HelpBorlandPage.Free;
end;
finally
MenuItems.Free;
end;
finally;
MainMenu.Free;
end;
end;

destructor TMyExpert.Destroy;
begin
FMyExpert.Free;
inherited Destroy;
end;

procedure TMyExpert.MyExpertClick(Sender: TIMenuItemIntf);
var
TM:TIModuleInterface;
TE:TIEditorInterface;
CW:TIEditWriter;
begin
TM:=ToolServices.GetModuleInterface(ToolServices.GetCurrentFile);
if TM<>nil then
begin
TE:=TM.GetEditorInterface;
if TE<>nil then
begin
CW:=TE.CreateWriter;
if CW<>nil then
begin
CW.Insert('沈前卫----恭喜发财,龙年吉祥'#13#10);
{...}
end;
CW.Free;
end;
TE.Free;
end;
TM.Free;
end;

procedure TMyExpert.Execute;
begin
end;

procedure DoneExpert; export;
begin
{ Put any general destruction code here. Note that the Delphi IDE
will destroy any experts which have been registered. }
end;

function InitExpert(ToolServices: TIToolServices;
RegisterProc: TExpertRegisterProc;
var Terminate: TExpertTerminateProc): Boolean; export; stdcall;
begin
if ExptIntf.ToolServices = nil then
begin
ExptIntf.ToolServices := ToolServices;
if ToolServices <> nil then
Application.Handle := ToolServices.GetParentHandle;
end;
Result := RegisterProc(TMyExpert.Create);
end;

exports
InitExpert name ExpertEntryPoint resident;

begin
end.
 
我查过很多资料,Delphi好象还不支持在Expert中插入的MenuItem的快捷键,
我用FMyExpert.SetShotCut返回True还是不行。
各位高手,为何不加入讨论呢? {B-(
 
老兄,你只要在CODE INSIDE的目录的
中输入就可以了.
 
to yeya:
我不懂你在说什么? {B-)
 
接受答案了.
 
后退
顶部