Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ]
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 20.09.2016, 03:57
Mikalas Mikalas вне форума
Прохожий
 
Регистрация: 20.09.2016
Сообщения: 2
Версия Delphi: Delphi XE4
Репутация: 10
Вопрос Перевод h в pas файл

Добрый день!
Перевожу заголовочный файл и сталкнулся с проблемой, что
разные типы данных имеют ссылку друг на друга
pcg_field_desc имеет ссылку на pcg_message_desc и наоборот

С++

Код:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
struct cg_message_desc_t;
 
/// Message field description
struct cg_field_desc_t {
    /// pointer to the next value
    struct cg_field_desc_t* next;
 
    /// Field ID. May be 0 if not defined
    uint32_t id;
 
    /// Field name
    char* name;
 
    /// Field description
    /// May be NULL if not defined
    char* desc;
 
    /// field type
    char* type;
 
    /// size in bytes
    size_t size;
 
    /// offset from buffer beginning
    size_t offset;
 
    /// Pointer to default value of the field
    /// Points to the buffer of size "size"
    /// May be NULL if no default value is defined
    void* def_value;
 
    /// Number of values for the field values
    size_t num_values;
 
    /// Pointer to the list of values
    /// which can be taken by the field
    struct cg_field_value_desc_t* values;
 
    /// Field options
    struct cg_value_pair_t* hints;
 
    /// Maximum number of fields, 1 by default
    size_t max_count;
 
    /// Link to description of count field
    struct cg_field_desc_t * count_field;
 
    /// Pointer to message description for type = 'm' fields
    struct cg_message_desc_t * type_msg;
};
 
// Index component description
struct cg_indexfield_desc_t {
    // Pointer to the next value
    struct cg_indexfield_desc_t* next;
 
    // points to field of index
    struct cg_field_desc_t* field;
 
    // sort order (0 for asc, 1 for desc)
    uint32_t sort_order;
};
 
// Index description
struct cg_index_desc_t {
    // Pointer to the next index
    struct cg_index_desc_t * next;
 
    // Number of fields in the index
    size_t num_fields;
 
    // Pointer to the first index component
    struct cg_indexfield_desc_t* fields;
 
    // name
    char* name;
 
    // desc
    // may be NULL if not defined
    char* desc;
 
    // index hints
    struct cg_value_pair_t* hints;
};
 
// Message description
struct cg_message_desc_t {
    // Pointer to the next message
    struct cg_message_desc_t* next;
 
    // Message data block size
    size_t size;
 
    // Number of fields in the message
    size_t num_fields;
 
    // Pointer to the first message description
    struct cg_field_desc_t* fields;
 
    // Message unique ID
    // May be 0 if not defined
    uint32_t id;
 
    // Message name
    // May be NULL if not defined
    char *name;
 
    // Description
    // May be NULL if not defined
    char *desc;
 
    // Message hints
    // May be NULL if not defined
    struct cg_value_pair_t* hints;
 
    // Number of indices for the message
    size_t num_indices;
 
    // Pointer to the first index description
    struct cg_index_desc_t* indices;
 
    // Size of alignment
    size_t align;
};

pascal

Код:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Message field description
type  pcg_field_desc = ^tcg_field_desc;
      tcg_field_desc = record
        next: pcg_field_desc;        // Pointer to the next value
        id: uint32_t;                // Field ID. May be 0 if not defined // May be NULL if not defined
        name: pAnsiChar;             // Field name  May be NULL if not defined
        desc: pAnsiChar;             // Description  May be NULL if not defined
        field_type: pAnsiChar;       // Field type
        size: size_t;                // Size in bytes
        offset: size_t;              // Offset from beginning of data in bytes
        def_value: Pointer;          // Pointer to default value of the field Points to the buffer of size "size" May be NULL if not defined
        num_values: size_t;          // Number of values for the field values
        values: pcg_field_value_desc;// Pointer to the list of values which can be taken by the field
        hints: pcg_value_pair;       // Field options
        max_count: size_t;           // Maximum number of fields, 1 by default
        count_field: pcg_field_desc; // Link to description of count field
        type_msg: pcg_message_desc;  // Pointer to message description for type = 'm' fields
      end;
 
 
// Index component description
type  pcg_indexfield_desc = ^tcg_indexfield_desc;
      tcg_indexfield_desc = record
        next: pcg_indexfield_desc;   // Pointer to the next value
        field: pcg_field_desc;       // Points to field of index
        sort_order: uint32_t;        // Sort order (0 for asc, 1 for desc)
      end;
 
// Index description
type pcg_index_desc = ^tcg_index_desc;
     tcg_index_desc = record
       next: pcg_index_desc;         // Pointer to the next index
       num_fields: size_t;           // Number of fields in the index
       fields: pcg_indexfield_desc;  // Pointer to the first index component
       name: pAnsiChar;              // Name
       desc: pAnsiChar;              // Desc
       hints: pcg_value_pair;        // index hints
     end;
 
// Message description
type  pcg_message_desc = ^tcg_message_desc;
      tcg_message_desc = record
        next: pcg_message_desc;      // Pointer to the next message
        size: size_t;                // Message data block size
        num_fields: size_t;          // Number of fields in the message
        fields: pcg_field_desc;      // Pointer to the first message description
        id: uint32_t;                // Message unique ID May be 0 if not defined
        name: pAnsiChar;             // Message name May be NULL if not defined
        desc: pAnsiChar;             // Description May be NULL if not defined
        hints: pcg_value_pair;       // message hints (in string format) May be NULL if not defined
        num_indices: size_t;         // Number of indices for the message
        indices: pcg_index_desc;     // Pointer to the first index description
        align: size_t;               // Size of alignment
      end;

Помогите решить проблему

Последний раз редактировалось Mikalas, 20.09.2016 в 04:06.
Ответить с цитированием
  #2  
Старый 20.09.2016, 06:35
lmikle lmikle вне форума
Модератор
 
Регистрация: 17.04.2008
Сообщения: 8,107
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
По умолчанию

что мешает разнести декларацию указателей и самих записей?
Код:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type
  pcg_field_desc = ^tcg_field_desc;
  pcg_message_desc = ^tcg_message_desc;
 
type
  tcg_field_desc = record
    ...
    type_msg: pcg_message_desc;
  end;
 
  tcg_message_desc = record
    ...
    fields: pcg_field_desc;
    ...
  end;
Ответить с цитированием
  #3  
Старый 20.09.2016, 09:23
icWasya icWasya вне форума
Местный
 
Регистрация: 09.11.2010
Сообщения: 499
Репутация: 10
По умолчанию

Надо их описывать в одном блоке type, вот так

Код:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type
  pcg_field_desc = ^tcg_field_desc;
  pcg_message_desc = ^tcg_message_desc;
  
//type<- это убрать
  tcg_field_desc = record
    ...
    type_msg: pcg_message_desc;
  end;
  
  tcg_message_desc = record
    ...
    fields: pcg_field_desc;
    ...
  end;
Ответить с цитированием
  #4  
Старый 20.09.2016, 14:15
Mikalas Mikalas вне форума
Прохожий
 
Регистрация: 20.09.2016
Сообщения: 2
Версия Delphi: Delphi XE4
Репутация: 10
По умолчанию

Спасибо, получилось
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 00:39.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025