Solved

Drawing a line in Borland Pascal 7.0

Posted on 1998-12-03
16
1,965 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
  • 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 20 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now