Drawing a line in Borland Pascal 7.0

I am trying to draw a line using borland pascal 7.0 for DOS on a PII 300MHz and Win95. I write the following code:

program lines;


uses crt,graph;

var gp,gm:integer;

begin

gp:=detect;
initgraph(gp,gm,'c:\borlandp\bgi\'); {where 'c:\borlandp\bgi\' is the directory of the BGI files on my PC}

line (10,10,20,20);

end.

And i'm keep getting the same error message:

BGI Error: Graphics not initialized (use InitGraph)

and i had used Initgraph.

Thanks anyway
Spyros Voutsinas
spyvouAsked:
Who is Participating?
 
jack_p50Commented:
Better use this awesome (up-to Hicolor) grafx unit that doesn't need any BGI and is ever faster than 16-color BGI. :   http://www.geocities.com/SiliconValley/Bay/9553/
(see source section)
0
 
VIBESPROCommented:
Try running it from DOS instead.

0
 
scrapdogCommented:
i presume this is a runtime error?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
vikiingCommented:
Upon completion of InitGraph procedure (and many other graph routines), you must call GraphResult function to get the error detected by it, if any. In addition to that, GraphErrorMsg function verboses numeric code into a string of the error message.

Thus, you should write:

InitGraph(gr, gm, <path>);
ErrorCode:=GraphResult;
{ grOK is a constant defined by Graph unit }
If ErrorCode<>grOK then
       Writeln('Error ' ,
           GraphErrorMsg(ErrorCode) ,
           ' in InitGraph');

That way you will know what happens with it.



0
 
scrapdogCommented:
Try this instead:

initgraph(gp,gm,' ');

 
0
 
vikiingCommented:
If you don't specify <path> in InitGraph procedure, you must use RegisterBGIFonts and RegisterBGIDriver procedures, so compiler will include all needed files into the .EXE (unless you're hapy with the question "Where are the files?" program will do when it runs).




0
 
spyvouAuthor Commented:
Ok vikiing i' ve done what you told me and know i get the following message:

ErrorDevice driver file not found (EGAVGA.BGI) in initgraph

and the file egavga.bgi is in the "c:\borlandp\bgi\ " directory

The value of the errorcode is -3.

Now what???

Thanks
Spyros Voutsinas

0
 
spyvouAuthor Commented:
Ok vikiing i' ve done what you told me and know i get the following message:

ErrorDevice driver file not found (EGAVGA.BGI) in initgraph

and the file egavga.bgi is in the "c:\borlandp\bgi\ " directory

The value of the errorcode is -3.

Now what???

Thanks
Spyros Voutsinas

0
 
My name is MudSystems EngineerCommented:
Usualy i don't "USE" the GRAPH unit, but if drawing a line its what you want why don't you doit directly to memory, thats it if you want to place a pixel, you have to do one of this lines (sopousing that yor in 320x200x256 MODE 13h):

    1:)    MEM[ X + Y * 320 ] = ColorOfPixel;
    2:)    BYTE( PTR( $A000,$0000 + X + Y * 320 ) ) =  ColorOfPixel

Ok, and what is a line, you say, well is a continues of points in this case pixels, so if you want to do an horizontal line you place a pixel in you starting coordinates (X1,Y1) and advance 1 place in memory to place the second pixel (X1+1, Y1), but if your doing a vertical line you have to advance 320 places in memory to place the next pixel (X1, Y1+1). hope with this you can do your line... :)
0
 
vikiingCommented:
I'm stunned. Error -3 means exactly that (file not found); I don't know what is the problem there. ¿Perhaps the file has "hidden" attribute set?. Look at the way I use graphic mode:

  { Register all drivers }
  if RegisterBGIdriver(@EGAVGADriverProc) < 0 then
       <Error loading EGA/VGA driver>
  if RegisterBGIdriver(@HercDriverProc) < 0 then
       <Error loading Hercules driver>
  { Register all the fonts }
  if RegisterBGIfont(@SmallFontProc) < 0 then
       <Error loading Small font>
  if RegisterBGIfont(@TriplexFontProc) < 0 then
       <all te same as before>

  GraphDriver:=Detect;
  InitGraph(GraphDriver, GraphMode, '');
  ErrorCode := GraphResult;             { preserve error return }
  if ErrorCode <> grOK then             { error? }
       <Error in InitGraph>

That directs the compiler to create a single .EXE file with all it needs into it. By doing this way, you have no need to carry on .BGI & .CHR files along with executable program; in fact, it runs without the existence of those nasty auxilliary files.

0
 
My name is MudSystems EngineerCommented:
I insist this BGI stuffs are so slow man, do it the hard way
0
 
vikiingCommented:
Whatboy:

With that criteria, I should stop working in high level languages, and must only program in assembler.

The idea of "too slow" or "too fast" depends on the application you develope. I created a "graphic" interpreter (to display tracing graphs I create with other programs) which works excellently good. Even with smoothing algorithms (spline curves) it performs OK. Thus, it really is NOT too slow for what I need.
0
 
InteqamCommented:
try to make sure that the graph.tpu unit is on the directory you specify in the initgraph call.

0
 
elkiorsCommented:
The too fast or too slow point doesn't come into it, he's running a PII 300.

If you're only displaying static screens then it isn't a problem, I've plotted curves and text quite happily on a 486.
0
 
My name is MudSystems EngineerCommented:
Ok you got me there, but why not try other posibilities, like using the line algoritmic, not using assembler, pure pascal and you learn how things do, sorry if i cause you trouble i wouldn't bother you again.
0
 
vikiingCommented:
Friend W'boy:

   Everybody can try whatever wants, and in fact, "try & error" is a good method to learn (perhaps a bit expensive). With more than 25 years working in this matter, you can imagine the amount of things I could tried.

But the initial question has nothing to do with assembly routines or any other stuff like that. Unfortunately, we don't have an Assembly Lang.forum (yet); but you can be sure that if we should do, it would be a pleasure.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.