Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2008.06.22;
Скачать: [xml.tar.bz2];

Вниз

Переменная классового типа   Найти похожие ветки 

 
DooRs   (2008-05-18 15:47) [0]

Доброе время суток!
Подскажите как создать переменную классового типа, например, a:array[0..500] of double;
Если модно, с кодом.
Заранее спасибо!


 
Юрий Зотов ©   (2008-05-18 15:57) [1]

Если это развод, то глупый.
Если нет, то - и где же в сабже класс?


 
Virgo_Style ©   (2008-05-18 16:07) [2]

рискну протелепатировать, что автор хочет иметь массив экземпляров класса.
Объявляется так же, только потом каждый экземпляр надо создать:

ArrayOfSomeClass[i]:=TSomeClass.Create(...);


 
DooRs   (2008-05-18 16:35) [3]


> Объявляется так же, только потом каждый экземпляр надо создать:
> ArrayOfSomeClass[i]:=TSomeClass.Create(...);

Спасибо
А как Set И Get расписывать?


 
Умище   (2008-05-18 17:03) [4]


> А как Set И Get расписывать?


Какой Set и Get?


 
DooRs   (2008-05-18 17:09) [5]

хм..Вот такой код у меня уже есть  - здесь я создаю класс и 2 переменные типа integer. Мне нужно создать еще одну переменную, типа array. По аналогии не получается - компилятор не принимает. Как можно это сделать?
Type
   TZat = class
   private

   FNach     : integer;
   FKon       : integer;
 
   public
   constructor Create;

   procedure SetNach   (New:integer);
   function  GetNach   : integer;

   procedure SetKon     (New:integer);
   function  GetKon     : integer;

property Nach   : integer read GetNach  write SetNach;
property Kon     : integer read GetKon    write SetKon;

end;


 
MBo ©   (2008-05-18 18:27) [6]

В справке
array properties

property Arr[Index: Integer]: Integer read GetArr write SetArr;


 
DooRs   (2008-05-18 19:15) [7]


> property Arr[Index: Integer]: Integer read GetArr write
> SetArr;

Пробовал.
Ошибка - несовместимы типы integer и array


 
MBo ©   (2008-05-18 19:17) [8]

В твоем случае с массивом вещественных будет property Arr[Index: Integer]: Double

>Пробовал.
Покажи, как пробовал


 
DooRs   (2008-05-18 19:49) [9]

unit Unit7;
interface
uses Graphics, SysUtils;
Type
   TZat = class

   private

   FNach     : integer;
   FKon       : integer;
   FZ : array[1..3]of integer;
   public
   constructor Create;

   procedure SetNach   (New:integer);
   function  GetNach   : integer;

   procedure SetZ(Index: integer;New:integer);
   function  GetZ(Index: integer):integer;

   procedure SetKon     (New:integer);
   function  GetKon     : integer;

property Nach   : integer read GetNach  write SetNach;
property Kon     : integer read GetKon    write SetKon;
property Z [Index: Integer]    : integer read GetZ    write SetZ;

end;

implementation

constructor TZat.Create;
begin
   inherited;

   FNach:=0;
   FKon:=0;
   //FZ:=0;
end;

procedure TZat.SetNach;
begin
    FNach:=New
end;
function TZat.GetNach;
begin
     Result:=FNach
end;

procedure TZat.SetKon;
begin
    FKon:=New
end;
function TZat.GetKon;
begin
     Result:=FKon
end;

procedure TZat.SetZ;
begin
    FZ:=New;
end;

function TZat.GetZ;
begin
     Result:=FZ[index]
end;

end.


 
Умище   (2008-05-18 19:59) [10]

Тэгами воспользоваться очень сложно?

unit Unit7;
interface
uses Graphics, SysUtils;
Type
  TZat = class

  private

  FNach     : integer;
  FKon       : integer;
  FZ : array[1..3]of integer;
  public
  constructor Create;

  procedure SetNach   (New:integer);
  function  GetNach   : integer;

  procedure SetZ(Index: integer;New:integer);
  function  GetZ(Index: integer):integer;

  procedure SetKon     (New:integer);
  function  GetKon     : integer;

property Nach   : integer read GetNach  write SetNach;
property Kon     : integer read GetKon    write SetKon;
property Z [Index: Integer]    : integer read GetZ    write SetZ;

end;

implementation

constructor TZat.Create;
begin
  inherited;

  FNach:=0;
  FKon:=0;
  //FZ:=0;
end;

procedure TZat.SetNach;
begin
   FNach:=New
end;
function TZat.GetNach;
begin
    Result:=FNach
end;

procedure TZat.SetKon;
begin
   FKon:=New
end;
function TZat.GetKon;
begin
    Result:=FKon
end;

procedure TZat.SetZ;
begin
   FZ:=New;
end;

function TZat.GetZ;
begin
    Result:=FZ[index]
end;

end.


 
DooRs   (2008-05-18 20:02) [11]

Сорри.

unit Unit7;
interface
uses Graphics, SysUtils;
Type
  TZat = class

  private

  FNach     : integer;
  FKon       : integer;
  FZ : array[1..3]of integer;
  public
  constructor Create;

  procedure SetNach   (New:integer);
  function  GetNach   : integer;

  procedure SetZ(Index: integer;New:integer);
  function  GetZ(Index: integer):integer;


  procedure SetKon     (New:integer);
  function  GetKon     : integer;

property Nach   : integer read GetNach  write SetNach;
property Kon     : integer read GetKon    write SetKon;
property Z [Index: Integer]    : integer read GetZ    write SetZ;

end;

implementation

constructor TZat.Create;
begin
  inherited;

  FNach:=0;
  FKon:=0;
  //FZ:=0;
end;

procedure TZat.SetNach;
begin
   FNach:=New
end;
function TZat.GetNach;
begin
    Result:=FNach
end;

procedure TZat.SetKon;
begin
   FKon:=New
end;
function TZat.GetKon;
begin
    Result:=FKon
end;

procedure TZat.SetZ;
begin
   FZ:=New;
end;


function TZat.GetZ;
begin
    Result:=FZ[index]
end;


end.


 
Anatoly Podgoretsky ©   (2008-05-18 20:28) [12]

FZ между прочим массив, а не ординальная переменная.


 
DooRs   (2008-05-18 20:30) [13]

Ну да...а что, так нельзя сделать?


 
Anatoly Podgoretsky ©   (2008-05-18 20:35) [14]

> DooRs  (18.05.2008 20:30:13)  [13]

Нельзя всему массиву присвоивать Integer
И ты до сих пор не указал строку с ошибкой.


 
DooRs   (2008-05-18 20:40) [15]

Подскажите, плиз, как тогда присвоить.
Сейчас укажу строку с ошибкой:

unit Unit7;
interface
uses Graphics, SysUtils;
Type
  TZat = class

  private

  FNach     : integer;
  FKon       : integer;
  FZ : array[1..3]of integer;
  public
  constructor Create;

  procedure SetNach   (New:integer);
  function  GetNach   : integer;

  procedure SetZ(Index: integer;New:integer);
  function  GetZ(Index: integer):integer;

  procedure SetKon     (New:integer);
  function  GetKon     : integer;

property Nach   : integer read GetNach  write SetNach;
property Kon     : integer read GetKon    write SetKon;
property Z [Index: Integer]    : integer read GetZ    write SetZ;

end;

implementation

constructor TZat.Create;
begin
  inherited;

  FNach:=0;
  FKon:=0;
  //FZ:=0;
end;

procedure TZat.SetNach;
begin
   FNach:=New
end;
function TZat.GetNach;
begin
    Result:=FNach
end;

procedure TZat.SetKon;
begin
   FKon:=New
end;
function TZat.GetKon;
begin
    Result:=FKon
end;

procedure TZat.SetZ;
begin
   FZ:=New;
end;

function TZat.GetZ;
begin
    Result:=FZ[index]
end;

end.


 
DooRs   (2008-05-18 20:41) [16]

прошу прощения.
Подскажите, плиз, как тогда присвоить.
Сейчас укажу строку с ошибкой:

unit Unit7;
interface
uses Graphics, SysUtils;
Type
 TZat = class

 private

 FNach     : integer;
 FKon       : integer;
 FZ : array[1..3]of integer;
 public
 constructor Create;

 procedure SetNach   (New:integer);
 function  GetNach   : integer;

 procedure SetZ(Index: integer;New:integer);
 function  GetZ(Index: integer):integer;

 procedure SetKon     (New:integer);
 function  GetKon     : integer;

property Nach   : integer read GetNach  write SetNach;
property Kon     : integer read GetKon    write SetKon;
property Z [Index: Integer]    : integer read GetZ    write SetZ;

end;

implementation

constructor TZat.Create;
begin
 inherited;

 FNach:=0;
 FKon:=0;
 //FZ:=0;
end;

procedure TZat.SetNach;
begin
  FNach:=New
end;
function TZat.GetNach;
begin
   Result:=FNach
end;

procedure TZat.SetKon;
begin
  FKon:=New
end;
function TZat.GetKon;
begin
   Result:=FKon
end;

procedure TZat.SetZ;
begin
  FZ:=New;
end;

function TZat.GetZ;
begin
   Result:=FZ[index]
end;

end.


 
Умище   (2008-05-18 21:35) [17]

Посмотри уже, в конце-концов, на свои процедуры SetXX. Они в определении класса у тебя принимают параметр, а в реализации - нет.
Кроме того, замени имя параметра New на другое. New - зарезервированное слово.

И почитай справку и литературу - как определяются классы.

Array Properties
Array properties are indexed properties. They can represent things like items in a list, child controls of a control, and pixels of a bitmap.

The declaration of an array property includes a parameter list that specifies the names and types of the indexes. For example,
property Objects[Index: Integer]: TObject read GetObject write SetObject;
property Pixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
property Values[const Name: string]: string read GetValue write SetValue;
The format of an index parameter list is the same as that of a procedure"s or function"s parameter list, except that the parameter declarations are enclosed in brackets instead of parentheses. Unlike arrays, which can use only ordinal-type indexes, array properties allow indexes of any type.

For array properties, access specifiers must list methods rather than fields. The method in a read specifier must be a function that takes the number and type of parameters listed in the property"s index parameter list, in the same order, and whose result type is identical to the property"s type. The method in a write specifier must be a procedure that takes the number and type of parameters listed in the property"s index parameter list, in the same order, plus an additional value or const parameter of the same type as the property.

For example, the access methods for the array properties above might be declared as
function GetObject(Index: Integer): TObject;
function GetPixel(X, Y: Integer): TColor;
function GetValue(const Name: string): string;
procedure SetObject(Index: Integer; Value: TObject);
procedure SetPixel(X, Y: Integer; Value: TColor);
procedure SetValue(const Name, Value: string);
An array property is accessed by indexing the property identifier. For example, the statements
if Collection.Objects[0] = nil then Exit;
Canvas.Pixels[10, 20] := clRed;
Params.Values["PATH"] := "C:\BIN";
correspond to
if Collection.GetObject(0) = nil then Exit;
Canvas.SetPixel(10, 20, clRed);
Params.SetValue("PATH", "C:\BIN");
The definition of an array property can be followed by the default directive, in which case the array property becomes the default property of the class. For example,
type
  TStringArray = class
   public
      property Strings[Index: Integer]: string ...; default;
         ...
   end;
If a class has a default property, you can access that property with the abbreviation object[index], which is equivalent to object.property[index]. For example, given the declaration above, StringArray.Strings[7] can be abbreviated to StringArray[7]. A class can have only one default property with a given signature (array parameter list), but it is possible to overload the default property. Changing or hiding the default property in descendant classes may lead to unexpected behavior, since the compiler always binds to properties statically.

----------------

Прошу прощения у модераторов за цитирование справки.


 
TForumHelp ©   (2008-05-29 10:54) [18]


> Если модно, с кодом.


помоему с кодом уже давно не модно! =)



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

Форум: "Начинающим";
Текущий архив: 2008.06.22;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.5 MB
Время: 0.045 c
2-1211976674
grav
2008-05-28 16:11
2008.06.22
Сравнение полей DOUBLE PRECISION в запросе


2-1211812095
Kolan
2008-05-26 18:28
2008.06.22
Font.Size в конструкторе TLabel не устанавливается


15-1210274134
-koha
2008-05-08 23:15
2008.06.22
Скрыть машину в локальной сети


4-1191393814
botaniQ
2007-10-03 10:43
2008.06.22
PopUpMenu и tray-приложение...


15-1210348051
wp2
2008-05-09 19:47
2008.06.22
Zyxel vs. D-Link (срочный вопрос)





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский