Recent

Author Topic: Control of class 'TImage'  (Read 4865 times)

sdfteh

  • Newbie
  • Posts: 6
Control of class 'TImage'
« on: November 04, 2016, 09:36:16 pm »
Hello, when I start my project shows up notification
  Control of class 'TImage' cant have control of class 'TImage' as a child

Code: Pascal  [Select][+][-]
  1. var
  2.   MainForm: TMainForm;
  3.   GameField:array[1..w,6..h] of TImage;
  4.   Next:array[1..5,1..5] of TImage;

one plase where I have TImage is

Code: Pascal  [Select][+][-]
  1. procedure printfield;  
  2. begin
  3.  chekline;
  4.  fallbrick;
  5.  for i:=1 to w do
  6.   for j:=1 to h do
  7.    begin
  8.     GameField[i,j]:=TImage.Create(MainForm);
  9.     GameField[i,j].Parent:=MainForm;
  10.     GameField[i,j].Height:=a;
  11.     GameField[i,j].Width:=a;
  12.     GameField[i,j].Top:=j*a+30;
  13.     GameField[i,j].left:=i*a+15
  14.    end;
  15.  for i:=1 to w do
  16.   for j:=1 to h do
  17.    if pole[i,j].sost then
  18.     GameField[i,j].Picture.LoadFromFile('.\img\'+IntToStr(pole[i,j].color)+'.png')
  19.    else
  20.     GameField[i,j].Picture.LoadFromFile('.\img\0.png');
  21.  for i:=1 to 5 do
  22.   for j:=1 to 5 do
  23.    if brick.amount[i,j] then
  24.     GameField[brick.x+i,brick.y+j].Picture.LoadFromFile('.\img\'+IntToStr(brick.col)+'.png');
  25.  for i:=1 to 5 do
  26.   for j:=1 to 5 do
  27.    begin
  28.     Next[i,j]:=TImage.Create(MainForm);
  29.     Next[i,j].Parent:=MainForm;
  30.     Next[i,j].Height:=a;
  31.     Next[i,j].Width:=a;
  32.     Next[i,j].Top:=j*a+60;
  33.     Next[i,j].left:=i*a+283
  34.    end;
  35.  for i:=1 to 5 do
  36.   for j:=1 to 5 do
  37.    if nextbrick.amount[i,j] then
  38.     Next[i,j].Picture.LoadFromFile('.\img\'+IntToStr(brick.col)+'.png')
  39.    else
  40.     Next[i,j].Picture.LoadFromFile('.\img\0.png');
  41. end;

Thanks

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: Control of class 'TImage'
« Reply #1 on: November 04, 2016, 10:00:42 pm »
Your code has missing variables that we can't assume. If you don't give us a project that can be compiled is not possible to help you.

sdfteh

  • Newbie
  • Posts: 6
Re: Control of class 'TImage'
« Reply #2 on: November 04, 2016, 10:28:10 pm »
Ok but its too big

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   StdCtrls;
  10.  
  11. const w=10; h=25; a=25; normal_tick=600; fast_tick=100;
  12.  
  13. type
  14.  
  15.   { TMainForm }
  16.  
  17.   TMainForm = class(TForm)
  18.     Score: TLabel;
  19.     StartBtn: TButton;
  20.     MainPanel: TPanel;
  21.     FrameTick: TTimer;
  22.     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  23.     procedure FrameTickTimer(Sender: TObject);
  24.     procedure StartBtnClick(Sender: TObject);
  25.   private
  26.     { private declarations }
  27.   public
  28.     { public declarations }
  29.   end;
  30.  
  31. var
  32.   MainForm: TMainForm;
  33.   GameField:array[1..w,6..h] of TImage;
  34.   Next:array[1..5,1..5] of TImage;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TMainForm }
  41. type figura = record
  42.                x,y,op,col,spin:integer;
  43.                amount: array[1..5,1..5] of boolean
  44.               end;
  45.  
  46. var
  47.  brick,nextbrick:figura;
  48.  pole:array[1..w,1..h] of record
  49.            color:integer;
  50.            sost:boolean;
  51.           end;
  52.  i,j,counter:integer;
  53.  
  54. procedure newbrick;   //создание новой фигуры
  55.   var option:integer;
  56. begin
  57.  for i:=1 to 5 do
  58.   for j:=1 to 5 do
  59.    brick.amount[i,j]:=nextbrick.amount[i,j];
  60.  brick.x:=nextbrick.x;
  61.  brick.y:=nextbrick.y;
  62.  brick.op:=nextbrick.op;
  63.  brick.col:=nextbrick.col;
  64.  brick.spin:=nextbrick.spin;
  65.  for i:=1 to 5 do
  66.   for j:=1 to 5 do
  67.    nextbrick.amount[i,j]:=false;
  68.  MainForm.FrameTick.Interval := normal_tick;
  69.  randomize;
  70.  nextbrick.x := Random(5)+1;
  71.  nextbrick.y := 1;
  72.  option:=random(7);
  73.  nextbrick.op:=option;
  74.  nextbrick.col:=random(7)+1;
  75.  nextbrick.col:=random(4);
  76.  case option of
  77.   0 : begin // J
  78.         nextbrick.amount[3,2]:=true;
  79.         nextbrick.amount[3,3]:=true;
  80.         nextbrick.amount[3,4]:=true;
  81.         nextbrick.amount[2,4]:=true
  82.        end;
  83.   1 : begin  //L
  84.         nextbrick.amount[3,2]:=true;
  85.         nextbrick.amount[3,3]:=true;
  86.         nextbrick.amount[3,4]:=true;
  87.         nextbrick.amount[4,4]:=true
  88.        end;
  89.   2 : begin  //S
  90.         nextbrick.amount[3,2]:=true;
  91.         nextbrick.amount[3,3]:=true;
  92.         nextbrick.amount[2,3]:=true;
  93.         nextbrick.amount[4,2]:=true
  94.        end;
  95.   3 : begin  //Z
  96.         nextbrick.amount[3,2]:=true;
  97.         nextbrick.amount[3,3]:=true;
  98.         nextbrick.amount[2,2]:=true;
  99.         nextbrick.amount[4,3]:=true
  100.        end;
  101.   4 : begin  //T
  102.         nextbrick.amount[3,2]:=true;
  103.         nextbrick.amount[3,3]:=true;
  104.         nextbrick.amount[2,3]:=true;
  105.         nextbrick.amount[4,3]:=true
  106.        end;
  107.   5 : begin  //I
  108.         nextbrick.amount[3,2]:=true;
  109.         nextbrick.amount[3,3]:=true;
  110.         nextbrick.amount[3,4]:=true;
  111.         nextbrick.amount[3,5]:=true
  112.        end;
  113.   6 : begin   //cube
  114.         nextbrick.amount[3,4]:=true;
  115.         nextbrick.amount[3,3]:=true;
  116.         nextbrick.amount[4,4]:=true;
  117.         nextbrick.amount[4,3]:=true
  118.        end;
  119.  end;
  120. end;
  121.  
  122. procedure chekline;     //проверка линии
  123. var line:array[6..h] of boolean;
  124.     k:integer;
  125. begin
  126.  for i:=h downto 6 do
  127.  begin
  128.   line[i]:=true;
  129.   for j:=1 to w do
  130.   begin
  131.    if not pole[j,i].sost then
  132.    begin
  133.     line[i]:= false;
  134.     break;
  135.    end;
  136.   end;
  137.   if line[i] then
  138.   begin
  139.    counter := counter + 1;
  140.    for j:=i downto 7 do
  141.     for k:=1 to w do
  142.      pole[j,k].sost:=pole[j-1,k].sost;
  143.    for j:=1 to w do
  144.     pole[6, j].sost:=false;
  145.   end;
  146.  MainForm.Score.Caption:='Счёт: '+IntToStr(counter);
  147.  end;
  148. end;
  149.  
  150. procedure fallbrick; //падение фигуры
  151. begin
  152.  if (brick.op<>6) then
  153.   if (brick.x>=w-4) then brick.x:=w-3
  154.   else if (brick.op<>7) then
  155.        begin
  156.         if (brick.x<=0) then brick.x:=1
  157.        end
  158.        else if (brick.x<=-1) then brick.x:=0
  159.  else if (brick.x<=-1) then brick.x:=0
  160.        else if (brick.x>=w-3) then brick.x:=w-2;
  161.   for i:=1 to w do
  162.    if (pole[i,6].sost) then
  163.    begin
  164.     MainForm.FrameTick.Enabled := false;
  165.     ShowMessage('Игра Окончена!');
  166.    end;
  167.   if brick.spin=0 then
  168.    case brick.op of
  169.     0:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) then  //J
  170.       begin
  171.         pole[brick.x+1,brick.y+3].sost:=true;
  172.         pole[brick.x+1,brick.y+3].color:=brick.col;
  173.         pole[brick.x+2,brick.y+3].sost:=true;
  174.         pole[brick.x+2,brick.y+3].color:=brick.col;
  175.         pole[brick.x+2,brick.y+2].sost:=true;
  176.         pole[brick.x+2,brick.y+2].color:=brick.col;
  177.         pole[brick.x+2,brick.y+1].sost:=true;
  178.         pole[brick.x+2,brick.y+1].color:=brick.col;
  179.         newbrick;
  180.        end;
  181.     1:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) then  //L
  182.       begin
  183.         pole[brick.x+3,brick.y+3].sost:=true;
  184.         pole[brick.x+3,brick.y+3].color:=brick.col;
  185.         pole[brick.x+2,brick.y+3].sost:=true;
  186.         pole[brick.x+2,brick.y+3].color:=brick.col;
  187.         pole[brick.x+2,brick.y+2].sost:=true;
  188.         pole[brick.x+2,brick.y+2].color:=brick.col;
  189.         pole[brick.x+2,brick.y+1].sost:=true;
  190.         pole[brick.x+2,brick.y+1].color:=brick.col;
  191.         newbrick;
  192.        end;
  193.     2: if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+2].sost) then  //S
  194.       begin
  195.         pole[brick.x+1,brick.y+2].sost:=true;
  196.         pole[brick.x+1,brick.y+2].color:=brick.col;
  197.         pole[brick.x+2,brick.y+2].sost:=true;
  198.         pole[brick.x+2,brick.y+2].color:=brick.col;
  199.         pole[brick.x+2,brick.y+1].sost:=true;
  200.         pole[brick.x+2,brick.y+1].color:=brick.col;
  201.         pole[brick.x+3,brick.y+1].sost:=true;
  202.         pole[brick.x+3,brick.y+1].color:=brick.col;
  203.         newbrick;
  204.        end;
  205.     3:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+2].sost) then  //Z
  206.       begin
  207.         pole[brick.x+3,brick.y+2].sost:=true;
  208.         pole[brick.x+3,brick.y+2].color:=brick.col;
  209.         pole[brick.x+2,brick.y+2].sost:=true;
  210.         pole[brick.x+2,brick.y+2].color:=brick.col;
  211.         pole[brick.x+2,brick.y+1].sost:=true;
  212.         pole[brick.x+2,brick.y+1].color:=brick.col;
  213.         pole[brick.x+1,brick.y+1].sost:=true;
  214.         pole[brick.x+1,brick.y+1].color:=brick.col;
  215.         newbrick;
  216.        end;
  217.     4:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then  //T
  218.       begin
  219.         pole[brick.x+3,brick.y+2].sost:=true;
  220.         pole[brick.x+3,brick.y+2].color:=brick.col;
  221.         pole[brick.x+2,brick.y+2].sost:=true;
  222.         pole[brick.x+2,brick.y+2].color:=brick.col;
  223.         pole[brick.x+2,brick.y+1].sost:=true;
  224.         pole[brick.x+2,brick.y+1].color:=brick.col;
  225.         pole[brick.x+1,brick.y+2].sost:=true;
  226.         pole[brick.x+1,brick.y+2].color:=brick.col;
  227.         newbrick;
  228.        end;
  229.     5:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+5].sost)  then  //I
  230.        begin
  231.         pole[brick.x+2,brick.y+1].sost:=true;
  232.         pole[brick.x+2,brick.y+1].color:=brick.col;
  233.         pole[brick.x+2,brick.y+2].sost:=true;
  234.         pole[brick.x+2,brick.y+2].color:=brick.col;
  235.         pole[brick.x+2,brick.y+3].sost:=true;
  236.         pole[brick.x+2,brick.y+3].color:=brick.col;
  237.         pole[brick.x+2,brick.y+4].sost:=true;
  238.         pole[brick.x+2,brick.y+4].color:=brick.col;
  239.         newbrick;
  240.        end;
  241.     6:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost)  or (pole[brick.x+3,brick.y+4].sost) then  //cube
  242.        begin
  243.         pole[brick.x+3,brick.y+3].sost:=true;
  244.         pole[brick.x+3,brick.y+3].color:=brick.col;
  245.         pole[brick.x+2,brick.y+3].sost:=true;
  246.         pole[brick.x+2,brick.y+3].color:=brick.col;
  247.         pole[brick.x+3,brick.y+2].sost:=true;
  248.         pole[brick.x+3,brick.y+2].color:=brick.col;
  249.         pole[brick.x+2,brick.y+2].sost:=true;
  250.         pole[brick.x+2,brick.y+2].color:=brick.col;
  251.         newbrick;
  252.        end;
  253.     end;
  254.  
  255.            

sdfteh

  • Newbie
  • Posts: 6
Re: Control of class 'TImage'
« Reply #3 on: November 04, 2016, 10:28:29 pm »
Code: Pascal  [Select][+][-]
  1. if brick.spin=1 then
  2.    case brick.op of
  3.     0:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then  //J
  4.        begin
  5.         pole[brick.x+3,brick.y+2].sost:=true;
  6.         pole[brick.x+3,brick.y+2].color:=brick.col;
  7.         pole[brick.x+2,brick.y+2].sost:=true;
  8.         pole[brick.x+2,brick.y+2].color:=brick.col;
  9.         pole[brick.x+1,brick.y+2].sost:=true;
  10.         pole[brick.x+1,brick.y+2].color:=brick.col;
  11.         pole[brick.x+1,brick.y+1].sost:=true;
  12.         pole[brick.x+1,brick.y+1].color:=brick.col;
  13.         newbrick;
  14.        end;
  15.     1:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+4].sost) then  //L
  16.        begin
  17.         pole[brick.x+3,brick.y+2].sost:=true;
  18.         pole[brick.x+3,brick.y+2].color:=brick.col;
  19.         pole[brick.x+2,brick.y+2].sost:=true;
  20.         pole[brick.x+2,brick.y+2].color:=brick.col;
  21.         pole[brick.x+1,brick.y+2].sost:=true;
  22.         pole[brick.x+1,brick.y+2].color:=brick.col;
  23.         pole[brick.x+1,brick.y+3].sost:=true;
  24.         pole[brick.x+1,brick.y+3].color:=brick.col;
  25.         newbrick;
  26.        end;
  27.     2:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+4].sost)  then  //S
  28.        begin
  29.         pole[brick.x+2,brick.y+1].sost:=true;
  30.         pole[brick.x+2,brick.y+1].color:=brick.col;
  31.         pole[brick.x+2,brick.y+2].sost:=true;
  32.         pole[brick.x+2,brick.y+2].color:=brick.col;
  33.         pole[brick.x+3,brick.y+2].sost:=true;
  34.         pole[brick.x+3,brick.y+2].color:=brick.col;
  35.         pole[brick.x+3,brick.y+3].sost:=true;
  36.         pole[brick.x+3,brick.y+3].color:=brick.col;
  37.         newbrick;
  38.        end;
  39.     3:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+3,brick.y+3].sost)  then  //S
  40.        begin
  41.         pole[brick.x+3,brick.y+1].sost:=true;
  42.         pole[brick.x+3,brick.y+1].color:=brick.col;
  43.         pole[brick.x+3,brick.y+2].sost:=true;
  44.         pole[brick.x+3,brick.y+2].color:=brick.col;
  45.         pole[brick.x+2,brick.y+2].sost:=true;
  46.         pole[brick.x+2,brick.y+2].color:=brick.col;
  47.         pole[brick.x+2,brick.y+3].sost:=true;
  48.         pole[brick.x+2,brick.y+3].color:=brick.col;
  49.         newbrick;
  50.        end;
  51.     4:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+3,brick.y+3].sost)  then  //T
  52.        begin
  53.         pole[brick.x+2,brick.y+1].sost:=true;
  54.         pole[brick.x+2,brick.y+1].color:=brick.col;
  55.         pole[brick.x+3,brick.y+2].sost:=true;
  56.         pole[brick.x+3,brick.y+2].color:=brick.col;
  57.         pole[brick.x+2,brick.y+2].sost:=true;
  58.         pole[brick.x+2,brick.y+2].color:=brick.col;
  59.         pole[brick.x+2,brick.y+3].sost:=true;
  60.         pole[brick.x+2,brick.y+3].color:=brick.col;
  61.         newbrick;
  62.        end;
  63.     5:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x,brick.y+3].sost) then  //I
  64.        begin
  65.         pole[brick.x+1,brick.y+2].sost:=true;
  66.         pole[brick.x+1,brick.y+2].color:=brick.col;
  67.         pole[brick.x+2,brick.y+2].sost:=true;
  68.         pole[brick.x+2,brick.y+2].color:=brick.col;
  69.         pole[brick.x+3,brick.y+2].sost:=true;
  70.         pole[brick.x+3,brick.y+2].color:=brick.col;
  71.         pole[brick.x,brick.y+2].sost:=true;
  72.         pole[brick.x,brick.y+2].color:=brick.col;
  73.         newbrick;
  74.        end;
  75.     6:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost)  or (pole[brick.x+2,brick.y+4].sost) then  //cube
  76.        begin
  77.         pole[brick.x+1,brick.y+3].sost:=true;
  78.         pole[brick.x+1,brick.y+3].color:=brick.col;
  79.         pole[brick.x+2,brick.y+3].sost:=true;
  80.         pole[brick.x+2,brick.y+3].color:=brick.col;
  81.         pole[brick.x+1,brick.y+2].sost:=true;
  82.         pole[brick.x+1,brick.y+2].color:=brick.col;
  83.         pole[brick.x+2,brick.y+2].sost:=true;
  84.         pole[brick.x+2,brick.y+2].color:=brick.col;
  85.         newbrick;
  86.        end;
  87.     end;
  88.   if brick.spin=2 then
  89.    case brick.op of
  90.     0:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+2].sost) or (pole[brick.x+2,brick.y+4].sost) then  //J
  91.        begin
  92.         pole[brick.x+3,brick.y+1].sost:=true;
  93.         pole[brick.x+3,brick.y+1].color:=brick.col;
  94.         pole[brick.x+2,brick.y+3].sost:=true;
  95.         pole[brick.x+2,brick.y+3].color:=brick.col;
  96.         pole[brick.x+2,brick.y+2].sost:=true;
  97.         pole[brick.x+2,brick.y+2].color:=brick.col;
  98.         pole[brick.x+2,brick.y+1].sost:=true;
  99.         pole[brick.x+2,brick.y+1].color:=brick.col;
  100.         newbrick;
  101.        end;
  102.     1:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+2].sost) or (pole[brick.x+2,brick.y+4].sost) then  //L
  103.        begin
  104.         pole[brick.x+1,brick.y+1].sost:=true;
  105.         pole[brick.x+1,brick.y+1].color:=brick.col;
  106.         pole[brick.x+2,brick.y+3].sost:=true;
  107.         pole[brick.x+2,brick.y+3].color:=brick.col;
  108.         pole[brick.x+2,brick.y+2].sost:=true;
  109.         pole[brick.x+2,brick.y+2].color:=brick.col;
  110.         pole[brick.x+2,brick.y+1].sost:=true;
  111.         pole[brick.x+2,brick.y+1].color:=brick.col;
  112.         newbrick;
  113.        end;
  114.     2: if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+3,brick.y+3].sost) then  //S
  115.        begin
  116.         pole[brick.x+1,brick.y+3].sost:=true;
  117.         pole[brick.x+1,brick.y+3].color:=brick.col;
  118.         pole[brick.x+2,brick.y+3].sost:=true;
  119.         pole[brick.x+2,brick.y+3].color:=brick.col;
  120.         pole[brick.x+2,brick.y+2].sost:=true;
  121.         pole[brick.x+2,brick.y+2].color:=brick.col;
  122.         pole[brick.x+3,brick.y+2].sost:=true;
  123.         pole[brick.x+3,brick.y+2].color:=brick.col;
  124.         newbrick;
  125.        end;
  126.     3:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+1,brick.y+3].sost) then  //Z
  127.        begin
  128.         pole[brick.x+3,brick.y+3].sost:=true;
  129.         pole[brick.x+3,brick.y+3].color:=brick.col;
  130.         pole[brick.x+2,brick.y+3].sost:=true;
  131.         pole[brick.x+2,brick.y+3].color:=brick.col;
  132.         pole[brick.x+2,brick.y+2].sost:=true;
  133.         pole[brick.x+2,brick.y+2].color:=brick.col;
  134.         pole[brick.x+1,brick.y+2].sost:=true;
  135.         pole[brick.x+1,brick.y+2].color:=brick.col;
  136.         newbrick;
  137.        end;
  138.     4:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+1,brick.y+3].sost) then  //T
  139.        begin
  140.         pole[brick.x+3,brick.y+2].sost:=true;
  141.         pole[brick.x+3,brick.y+2].color:=brick.col;
  142.         pole[brick.x+2,brick.y+2].sost:=true;
  143.         pole[brick.x+2,brick.y+2].color:=brick.col;
  144.         pole[brick.x+2,brick.y+3].sost:=true;
  145.         pole[brick.x+2,brick.y+3].color:=brick.col;
  146.         pole[brick.x+1,brick.y+2].sost:=true;
  147.         pole[brick.x+1,brick.y+2].color:=brick.col;
  148.         newbrick;
  149.        end;
  150.     5:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost)  then  //I
  151.         begin
  152.         pole[brick.x+2,brick.y].sost:=true;
  153.         pole[brick.x+2,brick.y].color:=brick.col;
  154.         pole[brick.x+2,brick.y+1].sost:=true;
  155.         pole[brick.x+2,brick.y+1].color:=brick.col;
  156.         pole[brick.x+2,brick.y+2].sost:=true;
  157.         pole[brick.x+2,brick.y+2].color:=brick.col;
  158.         pole[brick.x+2,brick.y+3].sost:=true;
  159.         pole[brick.x+2,brick.y+3].color:=brick.col;
  160.         newbrick;
  161.        end;
  162.     6:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+2].sost)  or (pole[brick.x+2,brick.y+2].sost) then  //cube
  163.         begin
  164.         pole[brick.x+1,brick.y+1].sost:=true;
  165.         pole[brick.x+1,brick.y+1].color:=brick.col;
  166.         pole[brick.x+2,brick.y+1].sost:=true;
  167.         pole[brick.x+2,brick.y+1].color:=brick.col;
  168.         pole[brick.x+1,brick.y+1].sost:=true;
  169.         pole[brick.x+1,brick.y+2].color:=brick.col;
  170.         pole[brick.x+2,brick.y+2].sost:=true;
  171.         pole[brick.x+2,brick.y+2].color:=brick.col;
  172.         newbrick;
  173.        end;
  174.     end;
  175.   if brick.spin=3 then
  176.    case brick.op of
  177.     0:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+4].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then  //J
  178.        begin
  179.         pole[brick.x+3,brick.y+2].sost:=true;
  180.         pole[brick.x+3,brick.y+2].color:=brick.col;
  181.         pole[brick.x+2,brick.y+2].sost:=true;
  182.         pole[brick.x+2,brick.y+2].color:=brick.col;
  183.         pole[brick.x+1,brick.y+2].sost:=true;
  184.         pole[brick.x+1,brick.y+2].color:=brick.col;
  185.         pole[brick.x+3,brick.y+3].sost:=true;
  186.         pole[brick.x+3,brick.y+3].color:=brick.col;
  187.         newbrick;
  188.        end;
  189.     1:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then  //L
  190.        begin
  191.         pole[brick.x+3,brick.y+2].sost:=true;
  192.         pole[brick.x+3,brick.y+2].color:=brick.col;
  193.         pole[brick.x+2,brick.y+2].sost:=true;
  194.         pole[brick.x+2,brick.y+2].color:=brick.col;
  195.         pole[brick.x+1,brick.y+2].sost:=true;
  196.         pole[brick.x+1,brick.y+2].color:=brick.col;
  197.         pole[brick.x+3,brick.y+1].sost:=true;
  198.         pole[brick.x+3,brick.y+1].color:=brick.col;
  199.         newbrick;
  200.        end;
  201.     2:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+4].sost)  then  //S
  202.        begin
  203.         pole[brick.x+1,brick.y+1].sost:=true;
  204.         pole[brick.x+1,brick.y+1].color:=brick.col;
  205.         pole[brick.x+1,brick.y+2].sost:=true;
  206.         pole[brick.x+1,brick.y+2].color:=brick.col;
  207.         pole[brick.x+2,brick.y+2].sost:=true;
  208.         pole[brick.x+2,brick.y+2].color:=brick.col;
  209.         pole[brick.x+2,brick.y+3].sost:=true;
  210.         pole[brick.x+2,brick.y+3].color:=brick.col;
  211.         newbrick;
  212.        end;
  213.     3:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost) or (pole[brick.x+2,brick.y+3].sost)  then  //S
  214.        begin
  215.         pole[brick.x+2,brick.y+1].sost:=true;
  216.         pole[brick.x+2,brick.y+1].color:=brick.col;
  217.         pole[brick.x+2,brick.y+2].sost:=true;
  218.         pole[brick.x+2,brick.y+2].color:=brick.col;
  219.         pole[brick.x+1,brick.y+2].sost:=true;
  220.         pole[brick.x+1,brick.y+2].color:=brick.col;
  221.         pole[brick.x+1,brick.y+3].sost:=true;
  222.         pole[brick.x+1,brick.y+3].color:=brick.col;
  223.         newbrick;
  224.        end;
  225.     4:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+1,brick.y+3].sost)  then  //T
  226.        begin
  227.         pole[brick.x+2,brick.y+1].sost:=true;
  228.         pole[brick.x+2,brick.y+1].color:=brick.col;
  229.         pole[brick.x+1,brick.y+2].sost:=true;
  230.         pole[brick.x+1,brick.y+2].color:=brick.col;
  231.         pole[brick.x+2,brick.y+2].sost:=true;
  232.         pole[brick.x+2,brick.y+2].color:=brick.col;
  233.         pole[brick.x+2,brick.y+3].sost:=true;
  234.         pole[brick.x+2,brick.y+3].color:=brick.col;
  235.         newbrick;
  236.        end;
  237.     5:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+4,brick.y+3].sost) then  //I
  238.        begin
  239.         pole[brick.x+1,brick.y+2].sost:=true;
  240.         pole[brick.x+1,brick.y+2].color:=brick.col;
  241.         pole[brick.x+2,brick.y+2].sost:=true;
  242.         pole[brick.x+2,brick.y+2].color:=brick.col;
  243.         pole[brick.x+3,brick.y+2].sost:=true;
  244.         pole[brick.x+3,brick.y+2].color:=brick.col;
  245.         pole[brick.x+4,brick.y+2].sost:=true;
  246.         pole[brick.x+4,brick.y+2].color:=brick.col;
  247.         newbrick;
  248.        end;
  249.     6:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+3].sost)  or (pole[brick.x+3,brick.y+3].sost) then  //cube
  250.        begin
  251.         pole[brick.x+3,brick.y+1].sost:=true;
  252.         pole[brick.x+3,brick.y+1].color:=brick.col;
  253.         pole[brick.x+2,brick.y+1].sost:=true;
  254.         pole[brick.x+2,brick.y+1].color:=brick.col;
  255.         pole[brick.x+3,brick.y+2].sost:=true;
  256.         pole[brick.x+3,brick.y+2].color:=brick.col;
  257.         pole[brick.x+2,brick.y+2].sost:=true;
  258.         pole[brick.x+2,brick.y+2].color:=brick.col;
  259.         newbrick;
  260.        end;
  261.     end;
  262. end;
  263.  
  264. procedure flipbrick; //поворот
  265.  var temp:boolean;
  266. begin
  267.  brick.spin:= brick.spin+1;
  268.  brick.spin:= brick.spin mod 4;
  269.  temp:=brick.amount[1,1];
  270.  brick.amount[1,1]:=brick.amount[1,5];
  271.  brick.amount[1,5]:=brick.amount[5,5];
  272.  brick.amount[5,5]:=brick.amount[5,1];
  273.  brick.amount[5,1]:=temp;
  274.  temp:=brick.amount[1,2];
  275.  brick.amount[1,2]:=brick.amount[2,5];
  276.  brick.amount[2,5]:=brick.amount[5,4];
  277.  brick.amount[5,4]:=brick.amount[4,1];
  278.  brick.amount[4,1]:=temp;
  279.  temp:=brick.amount[1,3];
  280.  brick.amount[1,3]:=brick.amount[3,5];
  281.  brick.amount[3,5]:=brick.amount[5,3];
  282.  brick.amount[5,3]:=brick.amount[3,1];
  283.  brick.amount[3,1]:=temp;
  284.  temp:=brick.amount[1,4];
  285.  brick.amount[1,4]:=brick.amount[4,5];
  286.  brick.amount[4,5]:=brick.amount[5,2];
  287.  brick.amount[5,2]:=brick.amount[2,1];
  288.  brick.amount[2,1]:=temp;
  289.  temp:=brick.amount[2,2];
  290.  brick.amount[2,2]:=brick.amount[2,4];
  291.  brick.amount[2,4]:=brick.amount[4,4];
  292.  brick.amount[4,4]:=brick.amount[4,2];
  293.  brick.amount[4,2]:=temp;
  294.  temp:=brick.amount[2,3];
  295.  brick.amount[2,3]:=brick.amount[3,4];
  296.  brick.amount[3,4]:=brick.amount[4,3];
  297.  brick.amount[4,3]:=brick.amount[3,2];
  298.  brick.amount[3,2]:=temp
  299. end;
  300.  
  301. procedure printfield;  //вывод поля
  302. begin
  303.  chekline;
  304.  fallbrick;
  305.  for i:=1 to w do
  306.   for j:=1 to h do
  307.    begin
  308.     GameField[i,j]:=TImage.Create(MainForm);
  309.     GameField[i,j].Parent:=MainForm;
  310.     GameField[i,j].Height:=a;
  311.     GameField[i,j].Width:=a;
  312.     GameField[i,j].Top:=j*a+30;
  313.     GameField[i,j].left:=i*a+15
  314.    end;
  315.  for i:=1 to w do
  316.   for j:=1 to h do
  317.    if pole[i,j].sost then
  318.     GameField[i,j].Picture.LoadFromFile('.\img\'+IntToStr(pole[i,j].color)+'.png')
  319.    else
  320.     GameField[i,j].Picture.LoadFromFile('.\img\0.png');
  321.  for i:=1 to 5 do
  322.   for j:=1 to 5 do
  323.    if brick.amount[i,j] then
  324.     GameField[brick.x+i,brick.y+j].Picture.LoadFromFile('.\img\'+IntToStr(brick.col)+'.png');
  325.  for i:=1 to 5 do
  326.   for j:=1 to 5 do
  327.    begin
  328.     Next[i,j]:=TImage.Create(MainForm);
  329.     Next[i,j].Parent:=MainForm;
  330.     Next[i,j].Height:=a;
  331.     Next[i,j].Width:=a;
  332.     Next[i,j].Top:=j*a+60;
  333.     Next[i,j].left:=i*a+283
  334.    end;
  335.  for i:=1 to 5 do
  336.   for j:=1 to 5 do
  337.    if nextbrick.amount[i,j] then
  338.     Next[i,j].Picture.LoadFromFile('.\img\'+IntToStr(brick.col)+'.png')
  339.    else
  340.     Next[i,j].Picture.LoadFromFile('.\img\0.png');
  341. end;
  342.  
  343. procedure TMainForm.StartBtnClick(Sender: TObject);
  344. begin
  345.   counter := 0;
  346.   newbrick;
  347.   newbrick;
  348.   for i:=1 to w do
  349.     for j:=1 to h do
  350.       pole[i,j].sost:=false;
  351. end;
  352.  
  353. procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
  354.   Shift: TShiftState);
  355. begin
  356.  if(not FrameTick.Enabled) then
  357.  begin
  358.    exit;
  359.  end;
  360.  if (Key = 37) then
  361.  begin
  362.    brick.x:=brick.x-1;
  363.    printfield;
  364.  end
  365.  else if (Key = 39) then
  366.  begin
  367.    brick.x := brick.x+1;
  368.    printfield;
  369.  end
  370.  else if (Key  = 40) then
  371.    Frametick.Interval:=fast_tick
  372.  else if (Key = 38) then
  373.   begin
  374.     flipbrick;
  375.     printfield;
  376.   end
  377. end;
  378.  
  379. procedure TMainForm.FrameTickTimer(Sender: TObject);
  380. begin
  381.   brick.y:=brick.y+1;
  382.   printfield
  383. end;
  384.  
  385. end.

sdfteh

  • Newbie
  • Posts: 6
Re: Control of class 'TImage'
« Reply #4 on: November 04, 2016, 10:34:51 pm »
image folder

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Control of class 'TImage'
« Reply #5 on: November 04, 2016, 10:38:09 pm »
Ok but its too big
That is why there is a option inside lazarus named publish project.

You can zip up that directory and attach it to a post.

The things you have posted is still not the complete project as it is missing the form(s) itself as wel as the project file.

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: Control of class 'TImage'
« Reply #6 on: November 04, 2016, 10:42:03 pm »
Remember to copy the images again when you publish, these get stripped from the publish with the default options.

If the size doesn't fit the forum restriction, upload it somewhere else like in Dropbox for example.

sdfteh

  • Newbie
  • Posts: 6
« Last Edit: November 04, 2016, 11:24:00 pm by sdfteh »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Control of class 'TImage'
« Reply #8 on: November 05, 2016, 01:19:28 am »
This took me a while to understand because error message is misleading.

You declared
Code: Pascal  [Select][+][-]
  1. GameField:array[1..w,6..h] of TImage;
(note the "6")
and then you loop
Code: Pascal  [Select][+][-]
  1. for i:=1 to w do
  2.   for j:=1 to h do
  3.    begin
  4.     GameField[i,j]:=TImage.Create(MainForm);
  5.     GameField[i,j].Parent:=MainForm;
which means that you access memory that is out of the array.

You can switch on Range checking in Projet Options / Debugging to catch this kind of bugs.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

sdfteh

  • Newbie
  • Posts: 6
Re: Control of class 'TImage'
« Reply #9 on: November 05, 2016, 09:51:02 am »
Thanks a lot men))

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Control of class 'TImage'
« Reply #10 on: November 05, 2016, 10:03:49 am »
Although not wrong, you should accustom yourself to begin array indexes with 0 (instead of 1) which is used all over Object Pascal. This way you can avoid the mind twist needed when handling both 0- and 1-based index conventions. Using both conventions will be a permant source of error, believe me.

 

TinyPortal © 2005-2018