We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Simple question about using Interface in Delphi

Mamouri
Mamouri asked
on
Medium Priority
1,188 Views
Last Modified: 2008-03-21
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?

Comment
Watch Question

Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Commented:
D := Direct3DCreate9(D3D_SDK_VERSION);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.