IDL与Delphi混合编程实现

转载请注明出处,谢谢!

其实与上篇IDL与C#混合编程实现是差不多的,不同的是Delphi安装IDL控件的方式。如图:






安装好后就会在Custom面板出现TIDLDrawWidget控件,不要忘了添加引用库路径。Delphi代码如下:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, IDLDRAWX3Lib_TLB, StdCtrls;

type
TForm1 = class(TForm)
IDLDrawWidget1: TIDLDrawWidget;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function IDLEstr(cmd: string): integer;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
IDLEstr(Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
var cmd: string;
begin
cmd := '@print';
IDLEstr('Restore,"print.sav"');//编译程序
IDLEstr(cmd);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
IDLDrawWidget1.IdlPath := 'IDL\include\bin.x86\idl.dll';
IDLDrawWidget1.InitIDL(Self.Handle);
end;

function TForm1.IDLEstr(cmd: string): integer;
var n: Integer;
begin
n := IDLDrawWidget1.ExecuteStr(cmd);
Result := n;
end;

end.

程序:

其中把IDLDrawWidget1.InitIDL(Self.Handle);改成IDLDrawWidget1.InitIDL(IDLDrawWidget1.Handle);就可以把IDL画的图画到窗体上去。