Solved

Drawing a line in Borland Pascal 7.0

Posted on 1998-12-03
16
1,977 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A Question about linking objects to ListView Items in Delphi 3 948
Extract text from webbrowser 5 1,394
Suppress UAC Prompt using shellapi 6 485
Creating a blank copy of a TClientDataSet 1 1,154
If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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