Board index » delphi » Why doesn't this work?

Why doesn't this work?

I translated this program from a TC++ book so I'm not really sure about
all the commands, but I *think* I got most of it right. This program is
apparantly supposed to show a ball spinning around with two-page
animation.  I can't get it to work at all, my computer hangs when I try
it. If you are wondering about the BGILink unit, it is a unit I made that
registers all the BGI drivers and fonts. If anyone can tell me why this
doesn't work (and any clues on how to make it work) I'd appreciate it.

Thanks in advance.

Yo, cut here--------------------------------------------------------------

program balls;
uses crt,graph,bgilink;
var ball   : array[1..6] of pointer;
    i,x    : integer;
    imsize : integer;
    Gdriver,GMode : Integer;

begin
  Gdriver := 3; {Loads EGA Driver}
  GMode := 1;   {Loads EGAHI Mode}
  InitGraph (GDriver,Gmode,'');
  rectangle(0,0,639,349);

  { Draw and Store Ball 1 }

  setcolor(15);
  ellipse(70,175,0,360,40,30);
  ellipse(70,175,0,360,15,30);
  setfillstyle(solidfill,1);
  floodfill(32,175,15);
  setfillstyle(solidfill,4);
  floodfill(70,175,15);
  setfillstyle(solidfill,2);
  floodfill(108,175,15);
  imsize := imagesize(30,145,110,205);
  getmem(ball[1],imsize);
  getimage(30,145,110,205,ball[1]);
  freemem (ball[1],imsize);

  { Draw and Store Ball 2 }

  setcolor(15);
  ellipse(170,175,0,360,40,30);
  ellipse(170,175,0,360,15,30);
  setfillstyle(solidfill,14);
  floodfill(132,175,15);
  setfillstyle(solidfill,1);
  floodfill(170,175,15);
  setfillstyle(solidfill,4);
  floodfill(208,175,15);
  imsize := imagesize(130,145,210,205);
  getmem(ball[2],imsize);
  getimage(130,145,210,205,ball[2]);
  freemem (ball[2],imsize);

  { Draw and Store Ball 3 }

  setcolor(15);
  ellipse(270,175,0,360,40,30);
  ellipse(270,175,0,360,15,30);
  setfillstyle(solidfill,3);
  floodfill(232,175,15);
  setfillstyle(solidfill,14);
  floodfill(270,175,15);
  setfillstyle(solidfill,1);
  floodfill(308,175,15);
  imsize := imagesize(230,145,310,205);
  getmem(ball[3],imsize);
  getimage(230,145,310,205,ball[3]);
  freemem (ball[3],imsize);

  { Draw and Store Ball 4 }

  setcolor(15);
  ellipse(370,175,0,360,40,30);
  ellipse(370,175,0,360,15,30);
  setfillstyle(solidfill,15);
  floodfill(332,175,15);
  setfillstyle(solidfill,3);
  floodfill(370,175,15);
  setfillstyle(solidfill,14);
  floodfill(408,175,15);
  imsize := imagesize(330,145,410,205);
  getmem(ball[4],imsize);
  getimage(330,145,410,205,ball[4]);
  freemem (ball[4],imsize);

  { Draw and Store Ball 5 }

  setcolor(15);
  ellipse(470,175,0,360,40,30);
  ellipse(470,175,0,360,15,30);
  setfillstyle(solidfill,2);
  floodfill(432,175,15);
  setfillstyle(solidfill,15);
  floodfill(470,175,15);
  setfillstyle(solidfill,3);
  floodfill(508,175,15);
  imsize := imagesize(430,145,510,205);
  getmem(ball[5],imsize);
  getimage(430,145,510,205,ball[5]);
  freemem (ball[5],imsize);

  { Draw and Store Ball 6 }

  setcolor(15);
  ellipse(570,175,0,360,40,30);
  ellipse(570,175,0,360,15,30);
  setfillstyle(solidfill,4);
  floodfill(532,175,15);
  setfillstyle(solidfill,2);
  floodfill(570,175,15);
  setfillstyle(solidfill,15);
  floodfill(608,175,15);
  imsize := imagesize(530,145,610,205);
  getmem(ball[6],imsize);
  getimage(530,145,610,205,ball[6]);
  freemem (ball[6],imsize);

  settextjustify(centertext,centertext);
  outtextxy(320,320,'Press Any Key to Continue');
  repeat until keypressed;

  clearviewport;
  rectangle(0,0,639,349);
  setactivepage(1);
  clearviewport;
  rectangle(0,0,639,349);

  repeat
    setactivepage(1);
    putimage(280,145,ball[1],copyput);
    setvisualpage(1);
    for i := 1 to 50 do begin pause; end;

    setactivepage(0);
    putimage(280,145,ball[2],copyput);
    setvisualpage(0);
    for i := 1 to 50 do begin pause; end;

    setactivepage(1);
    putimage(280,145,ball[3],copyput);
    setvisualpage(1);
    for i := 1 to 50 do begin pause; end;

    setactivepage(0);
    putimage(280,145,ball[4],copyput);
    setvisualpage(0);
    for i := 1 to 50 do begin pause; end;

    setactivepage(1);
    putimage(280,145,ball[5],copyput);
    setvisualpage(1);
    for i := 1 to 50 do begin pause; end;

    setactivepage(0);
    putimage(280,145,ball[6],copyput);
    setvisualpage(0);
    for i := 1 to 50 do begin pause; end;
  until keypressed;
  restorecrtmode;
  closegraph;
end.
------------------------------SNIP SNIP-----------------------------------

 

Re:Why doesn't this work?


Quote
In article <4aies0$...@news.nstn.ca> Jon Emmett <ag...@ccn.cs.dal.ca> writes:
>  imsize := imagesize(30,145,110,205);
>  getmem(ball[1],imsize);
>  getimage(30,145,110,205,ball[1]);
>  freemem (ball[1],imsize);

Why the freemem right after storing the image in the ball[1]?
(seems to me that the next getmem will grab the same memory just freed - and
lose your image? - I'd guess you'd want to freemem ONLY after you've finished
using ball[1], not right after you created it)

Max
(puzzled)

Re:Why doesn't this work?


Quote
Jon Emmett <ag...@ccn.cs.dal.ca> writes:
>  getmem(ball[1],imsize);
>  getimage(30,145,110,205,ball[1]);
>  freemem (ball[1],imsize);

The freemem command frees the memory the image is held in.

Put it at the end of your program!

Ciao
Dirk
--
"Hier ist es doof. Das Fruehstuecksbuffet ist zu karg und das Abendessen eine
Frechheit. Ibiza ist toll. Da gab es ein riesiges Fruehstuecksbuffet" -
"Mallorca ist auch gut. Da gab es Abends ordentlich was zu essen" -
"Fuerteventura ist auch nicht so schoen, der Kaffee..." - auf Kreta belauscht

Re:Why doesn't this work?


Quote
In article <4aies0$...@news.nstn.ca> Jon Emmett <ag...@ccn.cs.dal.ca> writes:
>From: Jon Emmett <ag...@ccn.cs.dal.ca>
>Subject: Why doesn't this work?
>Date: 11 Dec 1995 23:29:04 GMT
>I translated this program from a TC++ book so I'm not really sure about
>all the commands, but I *think* I got most of it right. This program is
>apparantly supposed to show a ball spinning around with two-page
>animation.  I can't get it to work at all, my computer hangs when I try
>it. If you are wondering about the BGILink unit, it is a unit I made that
>registers all the BGI drivers and fonts. If anyone can tell me why this
>doesn't work (and any clues on how to make it work) I'd appreciate it.
>Thanks in advance.
>Yo, cut here--------------------------------------------------------------
>program balls;
>uses crt,graph,bgilink;
>var ball   : array[1..6] of pointer;
>    i,x    : integer;
>    imsize : integer;
>    Gdriver,GMode : Integer;
>begin
>  Gdriver := 3; {Loads EGA Driver}
>  GMode := 1;   {Loads EGAHI Mode}
>  InitGraph (GDriver,Gmode,'');
>  rectangle(0,0,639,349);
>  { Draw and Store Ball 1 }
>  setcolor(15);
>  ellipse(70,175,0,360,40,30);
>  ellipse(70,175,0,360,15,30);
>  setfillstyle(solidfill,1);
>  floodfill(32,175,15);
>  setfillstyle(solidfill,4);
>  floodfill(70,175,15);
>  setfillstyle(solidfill,2);
>  floodfill(108,175,15);
>  imsize := imagesize(30,145,110,205);
>  getmem(ball[1],imsize);
>  getimage(30,145,110,205,ball[1]);
>  freemem (ball[1],imsize);
>  { Draw and Store Ball 2 }
>  setcolor(15);
>  ellipse(170,175,0,360,40,30);
>  ellipse(170,175,0,360,15,30);
>  setfillstyle(solidfill,14);
>  floodfill(132,175,15);
>  setfillstyle(solidfill,1);
>  floodfill(170,175,15);
>  setfillstyle(solidfill,4);
>  floodfill(208,175,15);
>  imsize := imagesize(130,145,210,205);
>  getmem(ball[2],imsize);
>  getimage(130,145,210,205,ball[2]);
>  freemem (ball[2],imsize);
>  { Draw and Store Ball 3 }
>  setcolor(15);
>  ellipse(270,175,0,360,40,30);
>  ellipse(270,175,0,360,15,30);
>  setfillstyle(solidfill,3);
>  floodfill(232,175,15);
>  setfillstyle(solidfill,14);
>  floodfill(270,175,15);
>  setfillstyle(solidfill,1);
>  floodfill(308,175,15);
>  imsize := imagesize(230,145,310,205);
>  getmem(ball[3],imsize);
>  getimage(230,145,310,205,ball[3]);
>  freemem (ball[3],imsize);
>  { Draw and Store Ball 4 }
>  setcolor(15);
>  ellipse(370,175,0,360,40,30);
>  ellipse(370,175,0,360,15,30);
>  setfillstyle(solidfill,15);
>  floodfill(332,175,15);
>  setfillstyle(solidfill,3);
>  floodfill(370,175,15);
>  setfillstyle(solidfill,14);
>  floodfill(408,175,15);
>  imsize := imagesize(330,145,410,205);
>  getmem(ball[4],imsize);
>  getimage(330,145,410,205,ball[4]);
>  freemem (ball[4],imsize);
>  { Draw and Store Ball 5 }
>  setcolor(15);
>  ellipse(470,175,0,360,40,30);
>  ellipse(470,175,0,360,15,30);
>  setfillstyle(solidfill,2);
>  floodfill(432,175,15);
>  setfillstyle(solidfill,15);
>  floodfill(470,175,15);
>  setfillstyle(solidfill,3);
>  floodfill(508,175,15);
>  imsize := imagesize(430,145,510,205);
>  getmem(ball[5],imsize);
>  getimage(430,145,510,205,ball[5]);
>  freemem (ball[5],imsize);
>  { Draw and Store Ball 6 }
>  setcolor(15);
>  ellipse(570,175,0,360,40,30);
>  ellipse(570,175,0,360,15,30);
>  setfillstyle(solidfill,4);
>  floodfill(532,175,15);
>  setfillstyle(solidfill,2);
>  floodfill(570,175,15);
>  setfillstyle(solidfill,15);
>  floodfill(608,175,15);
>  imsize := imagesize(530,145,610,205);
>  getmem(ball[6],imsize);
>  getimage(530,145,610,205,ball[6]);
>  freemem (ball[6],imsize);
>  settextjustify(centertext,centertext);
>  outtextxy(320,320,'Press Any Key to Continue');
>  repeat until keypressed;
>  clearviewport;
>  rectangle(0,0,639,349);
>  setactivepage(1);
>  clearviewport;
>  rectangle(0,0,639,349);
>  repeat
>    setactivepage(1);
>    putimage(280,145,ball[1],copyput);
>    setvisualpage(1);
>    for i := 1 to 50 do begin pause; end;
>    setactivepage(0);
>    putimage(280,145,ball[2],copyput);
>    setvisualpage(0);
>    for i := 1 to 50 do begin pause; end;
>    setactivepage(1);
>    putimage(280,145,ball[3],copyput);
>    setvisualpage(1);
>    for i := 1 to 50 do begin pause; end;
>    setactivepage(0);
>    putimage(280,145,ball[4],copyput);
>    setvisualpage(0);
>    for i := 1 to 50 do begin pause; end;
>    setactivepage(1);
>    putimage(280,145,ball[5],copyput);
>    setvisualpage(1);
>    for i := 1 to 50 do begin pause; end;
>    setactivepage(0);
>    putimage(280,145,ball[6],copyput);
>    setvisualpage(0);
>    for i := 1 to 50 do begin pause; end;
>  until keypressed;
>  restorecrtmode;
>  closegraph;
>end.
>------------------------------SNIP SNIP-----------------------------------

the problem is with your calls to GETIMAGE and PUTIMAGE.
the last parameter should be e.g. Ball[1]^ instead of Ball[1].

Other Threads