Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mutually dependent procedural variable and record

I have the following construct:

program Project26;

{$APPTYPE CONSOLE}
{$R *.res}
type

  TPrint_address_func = function(offset: integer; info: disassembler_info): boolean;

  disassembler_info = record
    data: string;
    print_address_func: TPrint_address_func;
  end;

begin
end.

Obvious either the record of the function-type needs to be declared in a forward declaration.
I know that I cannot declare the record as forward, but...

Is there a way to declare the procedural-variable as forward?
Or can I replace the record with an old-school object and declare that as forward?

like image 230
Johan Avatar asked Dec 13 '25 11:12

Johan


1 Answers

You cannot forward declare procedural types, or records. So, the conclusion is that you have to put the type definition inside the record:

type
  disassembler_info = record
  type
    TPrint_address_func = function(info: disassembler_info): boolean;
  var
    data: string;
    print_address_func: TPrint_address_func;
  end;

FWIW, once I start defining types inside records, I tend to start breaking the declaration up with visibility specifiers. I'd declare this type like this:

type
  disassembler_info = record
  public
    type
      TPrint_address_func = function(info: disassembler_info): boolean;
  public
    data: string;
    print_address_func: TPrint_address_func;
  end;
like image 54
David Heffernan Avatar answered Dec 15 '25 01:12

David Heffernan