• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1140
  • Last Modified:

Simple question about using Interface in Delphi

Hi,

How should create an Interface in delphi?
I want convert a code in C++ from here: http://www.codeproject.com/dialog/screencap.asp to delphi using Clootie DirectX Header available here: http://www.clootie.ru/delphi/download_dx92.html

here is my translated code from a function from this page http://www.clootie.ru/delphi/download_dx92.html

var
  D: IDirect3DDevice9;
  pSurface: IDirect3DSurface9;
begin
  D.CreateOffscreenPlainSurface(Screen.Width, Screen.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, nil);
  D.GetFrontBufferData(0, pSurface);
  D3DXSaveSurfaceToFile('Desktop.bmp',D3DXIFF_BMP,pSurface,nil,nil);


But it did not work because I should initialize IDirect3DDevice9 interface. Does somebody know how?

0
Mamouri
Asked:
Mamouri
  • 2
1 Solution
 
ziolkoCommented:
ISomeInterface = interface(IInterface)
[{interface GUID Ctrl +G}]
procedure SomeInterfaceMethod;
end;

TSomeImplementator = class(TInterfacedObject)
protected
  procedure SomeInterfaceMethod;
end;

...
procedure TSomeImplementator.SomeInterfaceMethod;
begin
  ShowMessage('hello world');
end;

...
var intf: ISomeInterface;

intf := TSomeImplementator.Create;
intf.SomeInterfaceMethod;
intf := nil;

ziolko.
0
 
ziolkoCommented:
if you want to use COM interface from 3rd party DLL the easiest way is to auto-generate interface declarations.

so if you have DLL register it with regsvr32 then in delphi go to Project -> Import Type Library then you will get XXX_TLB.pas file with declared interfaces AND functions like CoXXXCreate which will initialize interface for you

ziolko.
0
 
philipjcCommented:
D := Direct3DCreate9(D3D_SDK_VERSION);
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now