Delphi XE2: how to define not members of a class functions in the component unit

半城伤御伤魂 提交于 2019-12-25 17:47:05

问题


I have problem with not members of a class functions. I want to use that functions in a new component unit but they did not work in a component unit!

these two functions must assign to another function in a dll as parameter.

When I used this 2 functions(not members of class) in main form they can work but in the new component unit, the dll function cannot call back these two functions any more! How can I resolve this problem ? Is this delphi bug ? because I am using Delphi XE Update 2 this is lastest version of delphi maybe it is a bug!

  TComp12 = class(TCustomPanel)
  private
  ....
  protected
  ....
  public
  ....
  end;

  function function1(opaque: Pointer; plane: Pointer): Pointer; cdecl;
  function function2(opaque: Pointer; picture: Pointer; plane: Pointer) : Pointer; cdecl;

procedure Register;

implementation


procedure Register;
begin
  RegisterComponents('Comp1', [TComp12]);
end;

function function1(opaque: Pointer; plane: Pointer): Pointer; cdecl;
begin
......
end;
function function2(opaque: Pointer; picture: Pointer; plane: Pointer) : Pointer; cdecl;
begin
......
end;

回答1:


I looked at your code, and it is not a bug in Delphi.

There is a bug in the following code:

function VLCLock(opaque: Pointer; plane: Pointer): Pointer; cdecl;
var
  ctx: TCTX;
begin
  ctx := TCTX(opaque);
  Pointer(plane^) := @(ctx.FBuffer.StartLine[0]);
  Result := nil;
end;

TCTX(opaque) should be TCTX(opaque^). You must fix all similar occurrences in your code.




回答2:


I'm not clear what your question is, but I'm guessing:

1) perhaps you wrote some code in an older version of Delphi (your tags suggest perhaps even something ancient, like Delphi 7)

2) Your code is using "function pointers"

3) Your code might be trying to mix'n'match function pointers for free-standing functions (like function1 and function2, for example) with class method pointers.

If so, you can't do that :)

Here's a good link on Delphi function pointers. It should be 100% applicable to Delphi XE2:

http://delphi.about.com/od/objectpascalide/a/pointers.htm




回答3:


Yes it's a delphi XE2 bug, they accept that problem as bug http://qc.embarcadero.com/wc/qcmain.aspx?d=101180



来源:https://stackoverflow.com/questions/8206763/delphi-xe2-how-to-define-not-members-of-a-class-functions-in-the-component-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!