Bonjour,

voilà, j'essaie de convertir un type faisant partie d'un entête C sous Linux que j'ai convertit avec H2Pas :

Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
typedef struct
  {
    SANE_String_Const name;	/* name of this option (command-line name) */
    SANE_String_Const title;	/* title of this option (single-line) */
    SANE_String_Const desc;	/* description of this option (multi-line) */
    SANE_Value_Type type;	/* how are values interpreted? */
    SANE_Unit unit;		/* what is the (physical) unit? */
    SANE_Int size;
    SANE_Int cap;		/* capabilities */
 
    SANE_Constraint_Type constraint_type;
    union
      {
	const SANE_String_Const *string_list;	/* NULL-terminated list */
	const SANE_Word *word_list;	/* first element is list-length */
	const SANE_Range *range;
      }
    constraint;
  }
SANE_Option_Descriptor;

ce qui me pose problème c'est l'union. H2Pas l'a convertit en :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SANE_Option_Descriptor = record
      name : SANE_String_Const;
      title : SANE_String_Const;
      desc : SANE_String_Const;
      option_type : SANE_Value_Type;
      option_unit : SANE_Unit;
      size : SANE_Int;
      cap : SANE_Int;
      constraint_type : SANE_Constraint_Type;
      constraint : record
          case longint of
             0 : ( string_list : ^SANE_String_Const );
             1 : ( word_list : ^SANE_Word );
             2 : ( range : ^SANE_Range );
          end;
   end;
Ailleurs dans le code je n'arrive pas à récupérer 'constraint' quand je sais qu'il contient ^SANE_Range :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
PSANE_Option_Descriptor = ^SANE_Option_Descriptor;
saneoption: PSANE_Option_Descriptor;
range: ^SANE_Range;
 
range := saneoption^.constraint;
me donne :
demomain.pas(167,63) Error: Incompatible types: got "<record type>" expected "^SANE_Range"
Dans le record, j'ai modifié contraint par :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
SANE_Option_Descriptor = record
      name : SANE_String_Const;
      title : SANE_String_Const;
      desc : SANE_String_Const;
      option_type : SANE_Value_Type;
      option_unit : SANE_Unit;
      size : SANE_Int;
      cap : SANE_Int;
      constraint_type : SANE_Constraint_Type;
      case constraint: longint of
         0 : ( string_list : ^SANE_String_Const );
         1 : ( word_list : ^SANE_Word );
         2 : ( range : ^SANE_Range );
   end;
et j'obtiens :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
demomain.pas(167,63) Error: Incompatible types: got "LongInt" expected "^SANE_Range"
Maintenant il me renvoie un Longint au lieu d'un Record. Comment faire pour récupérer la valeur de 'contraint' dans le record ?

Qeul type