CnPack Forum


 
Subject: 求助几个问题
goldli
新警察
Rank: 1



UID 40224
Digest Posts 0
Credits 23
Posts 6
点点分 23
Reading Access 10
Registered 2008-5-16
Status Offline
Post at 2008-5-16 22:10  Profile | Blog | P.M. 
求助几个问题

都晚上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.
?
---------------------------------------
高人帮忙指正一下。
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-5-16 22:22  Profile | Blog | P.M. 
BorlandIDEService这个实例的类定义应该是一个TinterfaceObject后面附加了n多的接口,表示它实现了这么多接口。然后这个变量在BPL带包方式编译的情况下能被其他包引用,用Support或as转成需要的接口实例就可以用了。

内部实现上可能用了包容或聚合的模式,可以看看TAggregatedObject或TContainedObject的实现思想。
Top
 




All times are GMT++8, the time now is 2024-11-23 13:16

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.010697 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP