Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.11.14;
Скачать: CL | DM;

Вниз

Как в приведённом коде...   Найти похожие ветки 

 
^Sanya ©   (2002-11-05 15:31) [0]

Как в приведённом коде рациональней получить доступ к св-ву TBase.FileName (или полю FFileName) из класса TTable?
Поскольку они взаимосвязаны, наследовать один от другого не получается.
type
TTable = class
private
FName: string;
procedure SetCell(ACol, ARow: Integer; const Value: string);
function GetCell(ACol, ARow: Integer): string;
public
property Name: string read FName;
property Cells[Col, Row: Integer]: string read GetCell write SetCell;
constructor Create(ATableName: string);
end;

type
TBase = class
private
FFileName: string;
FTableCount: Integer;
procedure SetTableNames;
function GetTable(i: Integer): TTable;
public
property Tables[i: Integer]: TTable read GetTable;
property FileName: string read FFileName;
constructor Create(AFileName: string);
destructor Destroy;
end;

Прошу прощения за лишний код.
Вопрос должен быть простым, но создавать экземпляр класса TBase нельзя, т.к. параметр в TBase.Create и есть FileName.
Заранее благодарен.


 
MBo ©   (2002-11-05 15:36) [1]

пардон, а где в TBase внутреннее поле (или список) типа TTable?

BTW, нехорошо давать название, пересекающееся с имеющимся в VCL


 
Skier ©   (2002-11-05 15:36) [2]

>^Sanya
Не совсем понятна проблема...

> создавать экземпляр класса TBase нельзя


Почему нельзя ?
Нужны более подробные пояснения...
Да! И лучше всё-таки не называть свой класс TTable
(он уже есть...)



 
SaS13 ©   (2002-11-05 15:38) [3]

type
TBase = class

TTable = class
private
FBase: TBase;
FName: string;
procedure SetCell(ACol, ARow: Integer; const Value: string);
function GetCell(ACol, ARow: Integer): string;
public
property Base: TBase read FBase;
property Name: string read FName;
property Cells[Col, Row: Integer]: string read GetCell write SetCell;
constructor Create(ATableName: string);
end;

type
TBase = class
private
FFileName: string;
FTableCount: Integer;
procedure SetTableNames;
function GetTable(i: Integer): TTable;
public
property Tables[i: Integer]: TTable read GetTable;
property FileName: string read FFileName;
constructor Create(AFileName: string);
destructor Destroy;
end;
и добавить в constructor задание FBase


 
^Sanya ©   (2002-11-05 22:48) [4]


> MBo © (05.11.02 15:36)
> пардон, а где в TBase внутреннее поле (или список) типа
> TTable?

А зачем внутреннее поле типа TTable??? Ведь этот класс в TBase используется просто как тип данных.

> SaS13 © (05.11.02 15:38)

ЭТО КАК????? :
type
TBase = class

TTable = class
...
end;
Два класса в одном разделе type???
Я так не умею.
И что значит "задание FBase"?


 
SaS13 ©   (2002-11-06 09:13) [5]

^Sanya © (05.11.02 22:48)
Попробую объяснить:
type
tOneClass = class;
tTwoClass = class
protected
FOne : tOneClass;
public
constructor Create(AOne: tOneClass);
property One: tOneClass read FOne;
end;
tOneClass = class
protected
FNeedField: string;
public
property NeedField: string read FNeedField;
end;

implementation

//...

constructor tTwoClass.Create(AOne: tOneClass);
begin
// ...
FOne := AOne
end;


Тогда чтобы обратиться к FNeedField из tOneClass тебе надо будет просто написать: One.NeedField.
Уловил мысль?



Страницы: 1 вся ветка

Текущий архив: 2002.11.14;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.017 c
1-45956
Comp
2002-11-04 13:49
2002.11.14
И ещё...


1-45943
Krasuk
2002-11-04 11:51
2002.11.14
StringGrid


1-45949
prorok2
2002-11-04 12:34
2002.11.14
Вызов внешней программы и работа с ней


1-45878
Linder
2002-11-05 16:59
2002.11.14
число словами


1-45797
Lex
2002-11-04 21:27
2002.11.14
Как понять, что