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

Вниз

проблема с bitmap:=bitmap0;   Найти похожие ветки 

 
Роман   (2014-03-22 19:12) [0]

Добрый день, очень прошу помощи.
Подскажите,пож-та,
сразу покажу мой код:
uses
 Classes, SysUtils, Graphics;

type

   { TBase }

   TBase=class
      private
        x: Integer;
        y: Integer;
      public
        constructor Create(x0, y0: Integer);
        procedure setX (x0: Integer);
        procedure setY (y0: Integer);
        function  getX: Integer;
        function  getY: Integer;
   end;

   { TStatic }

   TStatic=class(TBase)
     private
       bitmap: TBitmap;
     public
       constructor Create(x0, y0: Integer; bitmap0: TBitmap);
       procedure setBitmap (bitmap0: TBitmap);
       function getBitmap: TBitmap;
   end;

   { TAnimate }

   TAnimate=class(TBase)
     private
        bitmap: array[0..100] of TBitmap;
        curFrame: Integer;
        maxFrame: Integer;
     public
       constructor Create(x0, y0: Integer; bitmap0: array of TBitmap;
         maxFrame0: Integer);
       procedure nextFrame;
       procedure setBitmap(bitmap0: array of TBitmap);
       function getCurFrame: Integer;
       function getMaxFrame: Integer;
       function getBitmap:TBitmap;
   end;

{ TAnimate }

constructor TAnimate.Create(x0, y0: Integer; bitmap0: array of TBitmap;
 maxFrame0: Integer);
begin
 x:=x0;
 y:=y0;
 bitmap:=bitmap0;
 curFrame:= 0;
 maxFRame:= maxFrame0;
end;

procedure TAnimate.nextFrame;
begin
 if curFrame < maxFrame then
    curFrame:=curFrame+1
 else
     curFrame:=0;
end;

procedure TAnimate.setBitmap(bitmap0: array of TBitmap);
begin
 bitmap:=bitmap0;
end;

function TAnimate.getCurFrame: Integer;
begin
 result:= curFrame;
end;

function TAnimate.getMaxFrame: Integer;
begin
 result:= maxFrame;
end;

function TAnimate.getBitmap: TBitmap;
begin
 result:=bitmap[curFrame];
end;

{ TStatic }

constructor TStatic.Create(x0, y0: Integer; bitmap0: TBitmap);
begin
 x:=x0;
 y:=y0;
 bitmap:=bitmap0;
end;

procedure TStatic.setBitmap(bitmap0: TBitmap);
begin
 bitmap:=bitmap0;
end;

function TStatic.getBitmap: TBitmap;
begin
 result:=bitmap;
end;

{ TBase }

constructor TBase.Create(x0, y0: Integer);
begin
 x:=x0;
 y:=y0;
end;

procedure TBase.setX(x0: Integer);
begin
 x:=x0;
end;

procedure TBase.setY(y0: Integer);
begin
 y:=y0;
end;

function TBase.getX: Integer;
begin
 result:=x;
end;

function TBase.getY: Integer;
begin
 result:=y;
end;

end.


Выдает ошибку Incompetible Types в:
constructor TAnimate.Create(x0, y0: Integer; bitmap0: array of TBitmap;
 maxFrame0: Integer);
begin
 bitmap:=bitmap0;            //вот в этом месте ошибка

Очень-очень сильно прошу помочь.
Видел в интернете описание с подобной ошибкой и пути решения, но так и не смог ее исправить.
Прошу подробного кода на данном примере


 
RWolf ©   (2014-03-22 19:33) [1]

нельзя присваивать открытый массив (array of в параметрах функции) обычному (array [0..100] of). Копируй поэлементно:
for i:=low(bitmap0) to high(bitmap0) do
 bitmap[i] := bitmap0[i]; //тут проверить на выход индекса за границы массива

а лучше вообще отказаться от array[0..100] в пользу динамического массива, например.


 
Константин 1   (2014-03-23 16:43) [2]


> bitmap:=bitmap0;

массив не присваивается в принципе,ибо будет скопирован лишь указатель на массив.
копирование можно делать как в [1], так и
bitmap := copy (bitmap0, 0, Length(bitmap0));,

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

for i:=low(bitmap0) to high(bitmap0) do
bitmap[i].Assign(bitmap0[i]);


 
Константин 1   (2014-03-23 16:48) [3]

а вообще ужасный код: куча названий bitmap, непонятно где что кем кого....



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

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

Наверх





Память: 0.46 MB
Время: 0.045 c
11-1259759327
MTsv DN
2009-12-02 16:08
2015.09.10
Разыскивается код...


6-1275567216
Eraser
2010-06-03 16:13
2015.09.10
Высоконагруженный TCP сервер


15-1421388097
Silvestr22
2015-01-16 09:01
2015.09.10
SSD кеш на неосновной диск - возможно ли ?


2-1396169201
Antonenko Aleks
2014-03-30 12:46
2015.09.10
Delphi XE5, как использовать буфер обмена на Андроид?


4-1271754311
QAZ
2010-04-20 13:05
2015.09.10
FindFirstFileW и FindNextFileW





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский