求助几个问题
都晚上10点了,哈哈。有几个点不清楚。
关于ToolsApi 里 borlandideservices 。它是一个接口变量 (Iborlandideservices )。不知道它的作用是什么,怎样实现它与其它接口的转换。
再者,delphi ide 是怎么处理这些接口,有个思路就好。
我自己弄个demo,但是总是在执行快完时报错。郁闷啊。
代码如下
-----------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ToolWin, ComCtrls, ImgList, Menus, ExtCtrls,IServices, StdCtrls;
type
TForm1 = class(TForm,IGTServices)
ToolBar1: TToolBar;
ImageList1: TImageList;
ToolButton1: TToolButton;
PopupMenu1: TPopupMenu;
ToolButton2: TToolButton;
sdfasd1: TMenuItem;
asdfa1: TMenuItem;
asdfasd1: TMenuItem;
PopupMenu2: TPopupMenu;
asdf1: TMenuItem;
sdasdf1: TMenuItem;
asdfasd2: TMenuItem;
asdfasdfasd1: TMenuItem;
MainMenu1: TMainMenu;
asdfasd3: TMenuItem;
asdfa2: TMenuItem;
asdfasdf1: TMenuItem;
asdfasd4: TMenuItem;
asdfasd5: TMenuItem;
asdfasdf2: TMenuItem;
ToolBar2: TToolBar;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
procedure ToolButton4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
function AddMaskedBmp(const Bmp:TBitmap;const TransparentColor:TColor):Integer;
function GetMainMenu():TMainMenu;
public
end;
var
Form1: TForm1;
iSer:IGTServices;
procedure addMenu(var ise:IGTServices); stdcall;external 'Project1.dll';
implementation
uses Unit2;
{$R *.dfm}
function TForm1.AddMaskedBmp(const Bmp: TBitmap;
const TransparentColor: TColor): Integer;
begin
ImageList1.AddMasked(Bmp,TransparentColor);
Result:=ImageList1.Count-1;
end;
function TForm1.GetMainMenu: TMainMenu;
begin
Result:=MainMenu1;
end;
procedure TForm1.ToolButton4Click(Sender: TObject);
begin
addMenu(iSer);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
iSer:=Self as IGTServices;
end;
end.
-------------------------------------------------------------------------------
unit IServices;
interface
uses Graphics,Menus;
type
//Tool services
IGTServices = interface
['{CE16E257-091A-4469-876A-468DEB40587D}']
function AddMaskedBmp(const Bmp:TBitmap;const TransparentColor:TColor):Integer;
function GetMainMenu():TMainMenu;
property MainMenu:TMainMenu read GetMainMenu;
end;
implementation
end.
?
-----------------------------------------------------------------------------
library Project1;
uses
SysUtils,
Classes,
Menus,
IServices in 'IServices.pas';
{$R *.res}
procedure addMenu(var ise:IGTServices); stdcall;
var
aser:IGTServices;
aItem:TMenuitem;
MM:TMainMenu;
begin
aser:=ise;
MM:=aser.MainMenu;
aItem:=TMenuItem.Create(mm);
aItem.Caption:='this is a menu';
MM.Items.Add(aItem);
end;
exports
addMenu;
begin
end.
?
---------------------------------------
高人帮忙指正一下。
|