Задача: При компиляции проекта возникает ошибка E2065 Unsatisfied forward or external declaration.
Инструментарий: Delphi
Решение:
При компиляции проекта появилась ошибка
[dcc32 Error] <Module Name>.pas(<Line Number>): E2065 Unsatisfied forward or external declaration: ‘<Class Name>.<Method Name>
Рассмотрим упрощенный вариант кода который привел к ошибке:
...
type
TA = class
public
procedure DoSomesting; // <= ошибка тут
end;
implementation
end.
В целом если рассмотреть упрощенны вариант все стает предельно ясно. Нет реализации для метода (в моем варианте это метод DoSomesting). Для решения проблемы — нужно добавить реализацию для метода.
...
type
TA = class
public
procedure DoSomesting;
end;
implementation
procedure TA.DoSomesting;
begin
//
end;
end.
PS: Для автоматической генерации метода в секции implementation можно воспользоваться сочетаем клавиш Ctrl+Shift+C. (Только сперва установите курсор в область описания класса). Если даже после автоматической генерации кода возникает та же ошибка — проверьте код, возможно у Вас используется конструкция {$IFDEF…}{$ELSE}{$ENDIF} и код попал в неиспользуемую секцию.
Go Up to Error and Warning Messages (Delphi)
This error message appears when you have a forward or external declaration of a procedure or function, or a declaration of a method in a class or object type, and you don’t define the procedure, function or method anywhere.
Maybe the definition is really missing, or maybe its name is just misspelled.
Note that a declaration of a procedure or function in the interface section of a unit is equivalent to a forward declaration — you have to supply the implementation (the body of the procedure or function) in the implementation section.
Similarly, the declaration of a method in a class or object type is equivalent to a forward declaration.
program Produce; type TMyClass = class constructor Create; end; function Sum(const a: array of Double): Double; forward; function Summ(const a: array of Double): Double; var i: Integer; begin Result := 0.0; for i:= 0 to High(a) do Result := Result + a[i]; end; begin end.
The definition of Sum in the above example has an easy-to-spot typo.
program Solve; type TMyClass = class constructor Create; end; constructor TMyClass.Create; begin end; function Sum(const a: array of Double): Double; forward; function Sum(const a: array of Double): Double; var i: Integer; begin Result := 0.0; for i:= 0 to High(a) do Result := Result + a[i]; end; begin end.
The solution: make sure the definitions of your procedures, functions and methods are all there, and spelled correctly.
The first problem is that you are not linking an external object. You would need to include:
{$LINK cGetLen.obj} // or whatever the object file is called
somewhere in the unit.
Once you’ve done that you will probably face another problem because the C compiler will decorate the name of the function. Typically, for a cdecl
function, by prefixing an underscore. So you would import the function like this:
function cGetLen(str1, str2: PAnsiChar): Integer ; cdecl; external name '_cGetLen';
or
function _cGetLen(str1, str2: PAnsiChar): Integer ; cdecl;
The other common problem you will face is that the C function calls other functions that cannot be resolved. They would need to be either implemented in separate object files that you linked, or implemented in your Pascal code.
Do bear in mind that I cannot see your C code, nor do I know how you compiled it. So, these problems may not afflict you, or indeed you may be facing other problems. An interop question like this really does demand full disclosure.
To be perfectly honest, you appear to be quite a long way from success here. I suggest you pause this task, and get a firm grasp of this subject matter. Start here: http://praxis-velthuis.de/rdc/articles/articles-cobjs.html
7kaa 0 / 0 / 0 Регистрация: 03.09.2013 Сообщений: 24 |
||||
1 |
||||
26.09.2013, 20:56. Показов 5396. Ответов 4 Метки нет (Все метки)
Ошибка: Помогите как решить. Я не разбирающийся человек в Delphi (Это домашнее задание).
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
26.09.2013, 20:56 |
Ответы с готовыми решениями: В коде выдает ошибку на 15 строчке. Мне надо исправить эту ошибку Программа которая выдает платформу компьютера выдает ошибку interface uses СМА Hansa PG5510A412 s/n 04454930213108 после нескольких минут выдает ошибку, выдает ошибку При решении программа выдаёт значение функции, равное 0 или выдаёт ошибку. Что не так? long Fact(short… 4 |
Супер-модератор 32627 / 21094 / 8139 Регистрация: 22.10.2011 Сообщений: 36,356 Записей в блоге: 8 |
|
26.09.2013, 20:59 |
2 |
как решить. Очень просто. Добавить реализацию метода FormCreate, или убрать 27-ю строку из исходника, если при создании формы не нужно производить никаких действий…
0 |
0 / 0 / 0 Регистрация: 03.09.2013 Сообщений: 24 |
|
26.09.2013, 21:01 [ТС] |
3 |
Очень просто. Добавить реализацию метода FormCreate, или убрать 27-ю строку из исходника, если при создании формы не нужно производить никаких действий… Реализация по сути же стоит? Можно чуть по-подробнее, я очень плохо разбираюсь
0 |
Супер-модератор 32627 / 21094 / 8139 Регистрация: 22.10.2011 Сообщений: 36,356 Записей в блоге: 8 |
|
26.09.2013, 21:04 |
4 |
Реализация по сути же стоит? Нет там реализации. Есть только заголовок метода.
Удалял — не помогло — вылетает ошибка. Какая ошибка? Сказки не надо рассказывать. Все, что может случиться — это Дельфи сообщит тебе, что на форме есть ссылка на несущесвующий метод, и предложит удалить ее. Нажмешь Yes, и все будет компилироваться прекрасно. Миниатюры
1 |
0 / 0 / 0 Регистрация: 03.09.2013 Сообщений: 24 |
|
26.09.2013, 21:13 [ТС] |
5 |
Нет там реализации. Есть только заголовок метода.Какая ошибка? Сказки не надо рассказывать. Все, что может случиться — это Дельфи сообщит тебе, что на форме есть ссылка на несущесвующий метод, и предложит удалить ее. Нажмешь Yes, и все будет компилироваться прекрасно. Все работает, спасибо.
0 |
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Menus; type TForm1 = class(TForm) mm1: TMainMenu; edt1: TEdit; edt2: TEdit; rb1: TRadioButton; rb2: TRadioButton; rb3: TRadioButton; rb4: TRadioButton; rb5: TRadioButton; rb6: TRadioButton; rb7: TRadioButton; rb8: TRadioButton; btn1: TButton; btn2: TButton; btn3: TButton; procedure rb1Click(Sender: TObject); procedure rb2Click(Sender: TObject); procedure rb4Click(Sender: TObject); procedure rb3Click(Sender: TObject); procedure rb5Click(Sender: TObject); procedure rb6Click(Sender: TObject); procedure rb8Click(Sender: TObject); procedure rb7Click(Sender: TObject); procedure btn1Click(Sender: TObject); PROCEDURE DEC_to_P(const st:string;p:byte;Sender: TObject); FUNCTION DEC_to_P0(const n:string;p:byte;Sender: TObject):string; PROCEDURE P_to_DEC(const n:string;p:byte;Sender: TObject); FUNCTION P0_to_DEC(const n:string;p:byte;Sender: TObject):string; PROCEDURE BIN_to_OCT(const n:string;Sender: TObject); PROCEDURE BIN_to_HEX(const n:string;Sender: TObject); PROCEDURE OCT_to_BIN(const n:string;Sender: TObject); PROCEDURE HEX_to_BIN(const n:string;Sender: TObject); PROCEDURE OCT_to_HEX(const st:string;Sender: TObject); PROCEDURE HEX_to_OCT(const st:string;Sender: TObject); procedure Edt1KeyPress(Sender: TObject; var Key: Char); procedure btn2Click(Sender: TObject); procedure btn3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const cod:array[0..15]of char= ('0','1','2','3','4','5','6','7','8','9','A','B','C','D', 'E','F'); cod2:array[0..7]of string[3]= ('000','001','010','011','100','101','110','111'); cod3:array[0..15]of string[4]= ('0000','0001','0010','0011','0100','0101','0110','0111', '1000','1001','1010','1011','1100','1101','1110','1111'); var Form1: TForm1; i:integer; tmp4:string; flag_clear:boolean; implementation {$R *.dfm} FUNCTION IsFloatBIN(ch:char; st:string):char; BEGIN IsFloatBIN:=chr(0); if (ch>='0')and(ch<='1') or(ch=#13)or(ch=#8) then IsFloatBIN:=ch; case ch of ',': if (Pos(',',st) = 0)and(st[Length(st)]>='0') then IsFloatBIN:=ch; end; END; FUNCTION IsFloatOCT(ch:char; st:string):char; BEGIN IsFloatOCT:=chr(0); if (ch>='0')and(ch<='7') or(ch=#13)or(ch=#8) then IsFloatOCT:=ch; case ch of ',': if (Pos(',',st) = 0)and(st[Length(st)]>='0') then IsFloatOCT:=ch; end; END; FUNCTION IsFloatDEC(ch:char; st:string):char; BEGIN IsFloatDEC:=chr(0); if (ch>='0')and(ch<='9')// Списала код Cyberforum! or(ch=#13)or(ch=#8) then IsFloatDEC:=ch; case ch of ',': if (Pos(',',st) = 0)and(st[Length(st)]>='0') then IsFloatDEC:=ch; end; END; FUNCTION IsFloatHEX(ch:char; st:string):char; BEGIN IsFloatHEX:=chr(0); case ch of 'Ф','ф': ch:='A'; 'И','и': ch:='B'; 'С','с': ch:='C'; 'В','в': ch:='D'; 'У','у': ch:='E'; 'А','а': ch:='F'; end; if (ch>='0')and(ch<='9') or(upcase(ch)>='A')and(upcase(ch)<='F') or(ch=#13)or(ch=#8) then IsFloatHEX:=upcase(ch); case ch of ',': if (Pos(',',st) = 0)and(st[Length(st)]>='0')then IsFloatHEX:=ch; end; END; procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char); begin edt2.Text:=''; if key=#13 then begin btn1.SetFocus; exit; end; if rb1.Checked then key:=IsFloatBIN(key,edt1.Text) else if rb2.Checked then key:=IsFloatOCT(key,edt1.Text) else if rb3.Checked then key:=IsFloatDEC(key,edt1.Text) else if rb4.Checked then key:=IsFloatHEX(key,edt1.Text); end; procedure TForm1.rb1Click(Sender: TObject); begin rb5.Enabled:=false; rb6.Enabled:=true; rb7.Enabled:=true; rb8.Enabled:=true; if rb5.Checked then rb6.Checked:=true; edt1.Text:='0'; edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb2Click(Sender: TObject); begin rb5.Enabled:=true; rb6.Enabled:=false; rb7.Enabled:=true; rb8.Enabled:=true; if rb6.Checked then rb5.Checked:=true; edt1.Text:='0'; edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb4Click(Sender: TObject); begin rb5.Enabled:=true; rb6.Enabled:=true; rb7.Enabled:=true; rb8.Enabled:=false; if rb8.Checked then rb7.Checked:=true; edt1.Text:='0'; edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb3Click(Sender: TObject); begin rb5.Enabled:=true; rb6.Enabled:=true; rb7.Enabled:=false; rb8.Enabled:=true; if rb7.Checked then rb6.Checked:=true; edt1.Text:='0'; edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb5Click(Sender: TObject); begin edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb6Click(Sender: TObject); begin edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb8Click(Sender: TObject); begin edt1.SetFocus; edt2.Text:=''; end; procedure TForm1.rb7Click(Sender: TObject); begin edt1.SetFocus; edt2.Text:=''; end; PROCEDURE TForm1.DEC_to_P(const st:string;p:byte;Sender: TObject); var ost,tmp,tmp2,b:string; d:longint; e,c:integer; BEGIN if pos(',',st)=0 then begin d:=strtoint(st); ost:=''; end else begin d:=strtoint(copy(st,1,pos(',',st)-1)); ost:=copy(st,pos(',',st)+1,length(st)-pos(',',st)); end; end; procedure TForm1.btn2Click(Sender: TObject); begin edt1.Clear; edt2.Clear; end; procedure TForm1.btn3Click(Sender: TObject); begin Form1.Close; end; end. |
Go Up to Error and Warning Messages (Delphi)
This error message appears when you have a forward or external declaration of a procedure or function, or a declaration of a method in a class or object type, and you don’t define the procedure, function or method anywhere.
Maybe the definition is really missing, or maybe its name is just misspelled.
Note that a declaration of a procedure or function in the interface section of a unit is equivalent to a forward declaration — you have to supply the implementation (the body of the procedure or function) in the implementation section.
Similarly, the declaration of a method in a class or object type is equivalent to a forward declaration.
program Produce; type TMyClass = class constructor Create; end; function Sum(const a: array of Double): Double; forward; function Summ(const a: array of Double): Double; var i: Integer; begin Result := 0.0; for i:= 0 to High(a) do Result := Result + a[i]; end; begin end.
The definition of Sum in the above example has an easy-to-spot typo.
program Solve; type TMyClass = class constructor Create; end; constructor TMyClass.Create; begin end; function Sum(const a: array of Double): Double; forward; function Sum(const a: array of Double): Double; var i: Integer; begin Result := 0.0; for i:= 0 to High(a) do Result := Result + a[i]; end; begin end.
The solution: make sure the definitions of your procedures, functions and methods are all there, and spelled correctly.
Delphi Compiler Error
E2065 Unsatisfied forward or external declaration ‘%s’
Reason for the Error & Solution
This error message appears when you have a forward or external declaration of a procedure or function, or a declaration of a method in a class or object type, and you don’t define the procedure, function or method anywhere.
Maybe the definition is really missing, or maybe its name is just misspelled.
Note that a declaration of a procedure or function in the interface section of a unit is equivalent to a forward declaration – you have to supply the implementation (the body of the procedure or function) in the implementation section.
Similarly, the declaration of a method in a class or object type is equivalent to a forward declaration.
program Produce; type TMyClass = class constructor Create; end; function Sum(const a: array of Double): Double; forward; function Summ(const a: array of Double): Double; var i: Integer; begin Result := 0.0; for i:= 0 to High(a) do Result := Result + a[i]; end; begin end.
The definition of Sum in the above example has an easy-to-spot typo.
program Solve; type TMyClass = class constructor Create; end; constructor TMyClass.Create; begin end; function Sum(const a: array of Double): Double; forward; function Sum(const a: array of Double): Double; var i: Integer; begin Result := 0.0; for i:= 0 to High(a) do Result := Result + a[i]; end; begin end.
The solution: make sure the definitions of your procedures, functions and methods are all there, and spelled correctly.