?
Solved

Drawing a line in Borland Pascal 7.0

Posted on 1998-12-03
16
Medium Priority
?
2,011 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:spyvou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +5
16 Comments
 
LVL 2

Expert Comment

by:VIBESPRO
ID: 1216297
Try running it from DOS instead.

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216298
i presume this is a runtime error?
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1216299
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
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
LVL 5

Expert Comment

by:scrapdog
ID: 1216300
Try this instead:

initgraph(gp,gm,' ');

 
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1216301
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
 

Author Comment

by:spyvou
ID: 1216302
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
 

Author Comment

by:spyvou
ID: 1216303
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
 
LVL 6

Expert Comment

by:My name is Mud
ID: 1216304
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
 
LVL 3

Expert Comment

by:vikiing
ID: 1216305
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
 
LVL 6

Expert Comment

by:My name is Mud
ID: 1216306
I insist this BGI stuffs are so slow man, do it the hard way
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1216307
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
 
LVL 7

Expert Comment

by:Inteqam
ID: 1216308
try to make sure that the graph.tpu unit is on the directory you specify in the initgraph call.

0
 

Expert Comment

by:elkiors
ID: 1216309
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
 
LVL 6

Expert Comment

by:My name is Mud
ID: 1216310
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
 
LVL 3

Expert Comment

by:vikiing
ID: 1216311
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
 
LVL 4

Accepted Solution

by:
jack_p50 earned 80 total points
ID: 1216312
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question