M
M
memradar2019-05-01 11:31:32
Delphi
memradar, 2019-05-01 11:31:32

How to translate optional parameters from C to Delphi?

When translating functions from C to Delphi, I encountered an interesting moment, in the header file in C, there is such a function declaration: The
5cc9593b7830a385091610.png
question is how to correctly implement this function in Delphi (my version, only the first two parameters)?

function Vix_GetProperties(handle: VixHandle;
                           firstPropertyID: VixPropertyID
                           ): VixError; cdecl; external 'vix.dll';

Unfortunately, I did not find examples of how to transfer such things '...' as a parameter from C to Delphi...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
memradar, 2019-05-01
@memradar

function Vix_GetProperties(
  handle: VixHandle;
  firstPropertyID: VixPropertyID
): VixError; cdecl varargs; external 'vix.dll';

After cdecl add varargs. This allows the remote library to tell the compiler that we can pass arguments as a list.
Thank you all very much!

R
Rsa97, 2019-05-01
@Rsa97

Only by passing parameters in an array.

procedure TForm1.Display(X: array of const);
var
  I: Integer;
begin
  for I := Low(X) to High(X) do
  ...
end;

Display([42, 1.234, 'A', 'Васек Трубачев', Form1, TButton]);

K
Konstantin Tsvetkov, 2019-05-01
@tsklab

Vix_GetPropertiesworks similarly WriteLnwith a list.

Predefined constants, types, procedures, and functions (such as True, Integer, or Writeln) do not have actual declarations.Instead they are built into the compiler and are treated as if they were declared at the beginning of the System unit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question