Solved

Drawing a line in Borland Pascal 7.0

Posted on 1998-12-03
16
1,970 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net code to pascal 1 391
ROUND() from fbudf.dll only gives integers 2 1,045
Pascal equivalent of VB Select/case 3 339
How to capture screen window of a process 4 398
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

16 Experts available now in Live!

Get 1:1 Help Now