Just a few questions:-

  1. Can you add colours?
  2. Can you create boxes?
  3. Can you update constants?
  4. can you create drop down boxes?
  5. can u assign a keyboard key to a letter/number?
  6. is there something so when you press a key that the window closes?

thank you
:):)

Yes to all.

However:

  1. How do you mean? What colors and where?
  2. Again, how do you mean?
  3. Constants should be constant..., but a quirk of early Turbo Pascal dialects is retained as an option to make typed constants pretty much the same thing as initialized variables.
    You should, in new code, keep constants constant and use initialized variables for mutable things.
  4. Windows provides a control for that. In Delphi, just drop a tComboBox on the form.
  5. What exactly do you want to do to the keyboard?
  6. Write a OnKeyPress or OnKeyDown event handler method (use the first for normal keys, and the second for special keys like F1 and arrow keys):
    procedure Form1.OnKeyDown(
      sender:  tObject;
      var key: word;
      shift:   tShiftState
      );
      begin
      // Tell the form to close if F10 is pressed
      if (key = VK_F10) and (shift = []) then close
      end;

    For this to work make sure to use the Object Inspector to set the form's KeyPreview property to true.

Hope this helps.

im using turbo pascal

1+2 dont matter, i am not too worried about the color things and stuff i got that working

but 3 does, say the price=99.9 and i use price as a constant everywhere but i also have to do where the price can be updates how would i do that

4+5 dont matter i tihnk i got round those somehow lol

but 6 is intresting, that code you have writen that isnt psacal isit?, if it isnt how would you do that on pascal

thanks 4 the help
:)

Ah, your talk of drop-down boxes and windows made me think you were using a GUI environment. The code I posted is for Delphi, which is Object Pascal.

In Turbo Pascal, start up the editor and press F1 twice. Then highlight the "Crt" item and press ENTER. All the stuff to play with colors is in there. You can specify a color directly with the TextAttr variable.


For constants, you'll have to use "typed constants", which are writable in TP4+.

const price: real = 12.99;
begin
  write( 'Price was: ', price:0:2, ', but now it is: ' );
  price := 5.99;
  writeln( price:0:2, '! What a deal!' )
end.

I hope this helps.


Oh yeah, before I forget. You can do windowing stuff if you get the Turbo Vision text GUI. I think you can google it. It gives you combo boxes and the like. For simple projects, though, it isn't worth the grief...


I don't know if you can close the window when you quit... I'll have to think about it a bit.

i have done wht u have done for the price thingy but, when i go onto to use the price later on it still is 12.99 or whatever in my case

I tested with TP4.

Just copy the code snippit I gave you to a text file (like "foo.pas") and compile it. (Don't change it in any way.)

Tell me what errors it gives you.

no errors BUT, i have extened this so that i want to use 5.99 price later on but when i try and use the 5.99 the 12.99 replaces it because its a constant

Typed constants are not true constants in TP. If you change it it stays changed.

Which means something else is wrong with your code. Post it and I'll take a look and see if I can find what's wrong.

yo could i email it to you because its about the petrol pump and i dont wnt people stealing it

i just got it working mate :D:D:D

thank 4 ur help

but i was wondering about the colour on pascal i dont know what to do for that

Use the TextColor and TextBackground procedures. The colors are defined as constants in the CRT unit: Black, Blue, Green, Cyan, etc.

If you plan to set the background color to DarkGray, LightBlue, etc. make sure to call HighVideo at the beginning of your program (so that your letters don't blink).

For example:

uses CRT;
begin
  HighVideo;
  TextBackground( White );
  TextColor( Black );
  ClrScr;
  GotoXY( 34, 12 );
  Write( 'Hello World!' );
  Readln
end.

Hope this helps.

it says comes up with an error, firstly saying crt.tpu not found then when i change crt to wincrt it doesnt recognise the TextColor and TextBackground

You're using BP7, right?

I've googled a bit and it appears that BP7's WinCRT unit doesn't have those routines. Yes, I agree that's insane!

If you were just using the CRT unit I'd tell you to use the BIOS interrupts to set the output color, but I'm not sure what to do about the WinCRT routines...

Sorry. :S

There are many time that I stop to use BP/BPW but I think I can help with this thread. Let me try...

it says comes up with an error, firstly saying crt.tpu not found then when i change crt to wincrt it doesnt recognise the TextColor and TextBackground

Are You sure that the error message shows crt.tpu and not crt.tpw?

I question You about this because You have compiled your program with WinCrt but without similar error (except by TextColor and TextBackGround error messages). It's make me to think that You are compiling your program using Windows target option - checkout on menu options Compile->Target.... Try change to Real mode Application or Protected mode Application option and then use CRT unit and compile your program again.

You're using BP7, right?

I've googled a bit and it appears that BP7's WinCRT unit doesn't have those routines. Yes, I agree that's insane!

(...), but I'm not sure what to do about the WinCRT routines...

Duoas, You are right. WinCRT just create a simple window (similar to console application) and emule some minimals CRT functions.

If you were just using the CRT unit I'd tell you to use the BIOS interrupts to set the output color

This is basically that the CRT unit use - intialize TextAttr (when TextColor and TextBackGround is invoked) and use than as parameter when INT &10 is called.


Bye

This article has been dead for over six months. Start a new discussion instead.