Форум: "Основная";
Текущий архив: 2009.12.20;
Скачать: [xml.tar.bz2];
ВнизПроблема организации кода из нескольких модулей Найти похожие ветки
← →
VoyagerEternal © (2008-12-21 09:11) [0]--Первый вопрос--
Есть два модуля, каждый из которых ссылается на другой модуль:
unit UnitA;
uses UnitB;
type
TClass1 = class
x: TClass2;
end;
implementation
...
end.
unit UnitB;
uses UnitA; //здесь ошибка
type
TClass2 = class
x: TClass1;
end;
implementation
...
end.
[Fatal Error] MK_STR.pas(5): Circular unit reference to "UnitA"
и чо делать? - я хочу чтоб каждый класс был в отдельном файле, они очень большие
(иначе каша получится), у меня уже несколько раз возникала такая проблема
Как правильно организовать код?
--Второй вопрос--
Есть несколько модулей: Unit1, Unit2, .... Unit20, где написаны самые мои наработки, которые я использую во всех своих проектах.
Не хочу писать длинную строчку: uses Unit1, Unit2, .... Unit20; в каждом модуле своего нового проекта.
Хочу написать uses UnitALL; и все
как это сделать?
← →
PZ (2008-12-21 09:18) [1]1.
unit UnitA;
type
TClass1 = class
x: TClass2;
end;
implementation
uses UnitB;
...
end.
unit UnitB;
type
TClass2 = class
x: TClass1;
end;
implementation
uses UnitA;
...
end.
← →
VoyagerEternal © (2008-12-21 09:36) [2]>PZ
TClass1 = class
x: TClass2; --> [Error] UnitA.pas(10): Undeclared identifier: "TClass2"
end;
← →
PZ (2008-12-21 09:48) [3]Не обратил внимания.
Видимо надо организовать общий модуль UnitС, где и определить модули UnitA и UnitВ
← →
VoyagerEternal © (2008-12-21 10:54) [4]Попытка создать общий модуль UnitC.
--Попытка первая--unit UnitC;
interface
type
TClass1 = class; //[Error] UnitC.pas(7): Type "TClass1" is not yet completely defined
TClass2 = class; //[Error] UnitC.pas(7): Type "TClass1" is not yet completely defined
implementation
end.
--Вторая вторая--unit UnitC;
interface
type
TClass1 = class end;
TClass2 = class end;
implementation
end.unit UnitB;
interface
uses UnitC;
type
TClass2 = class
c1: TClass1;
function sin(x: Extended): Extended;
end;
implementation
function TClass2.sin(x: Extended): Extended;
begin
sin := System.sin(x);
end;
end.unit UnitA;
interface
uses UnitC;
type
TClass1 = class
c2: TClass2;
function cos(x: Extended): Extended;
function sin2(x: Extended): Extended;
end;
implementation
function TClass1.cos(x: Extended): Extended;
begin
cos := System.cos(x);
end;
function TClass1.sin2(x: Extended): Extended;
begin
sin2 := sqr( c2.sin(x) );//класс c2 пустой нет там функции sin() //[Error] UnitA.pas(23): Undeclared identifier: "sin"
end;
end.
← →
sniknik © (2008-12-21 14:00) [5]
unit Unit1;
interface
type
TClass2 = class
c1: TClass;
function sin(x: Extended): Extended;
end;
TClass1 = class
c2: TClass;
function cos(x: Extended): Extended;
function sin2(x: Extended): Extended;
end;
implementation
function TClass2.sin(x: Extended): Extended;
begin
sin := System.sin(x);
end;
function TClass1.cos(x: Extended): Extended;
begin
cos := System.cos(x);
end;
function TClass1.sin2(x: Extended): Extended;
begin
sin2 := sqr( TClass2(c2).sin(x) );
end;
end.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2009.12.20;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.005 c