Pascal Misc |
|
Any questions send them to pascalmisc@teentwo.8m.com 1. How to use a mouse: To use a mouse you will need the unit, mouselib(you can
download it from our download menu). To get the mouse cursor visible in text you must
enter INITMOUSE; and then SHOWMOUSECURSOR;. To get it visible in graphics
just type SHOWMOUSECURSOR;. EXAMPLE: Uses Var Begin When in graphics you can change the mouse pointer. There
are 10 preset mouse pointers, to use them type: Download the unit here, mouse.zip Any questions send them to pascalmisc@teentwo.8m.com 2. How to use a sounblaster or compatible To use a sound blaster you will need the SMIX121 units witch is available at our download menu. Before I continue just a special thanks to ETHANE BRODSKY for the unit. The sounds you are going to use must be 22MHZ, mono 8 bit, wave file. You must then convert it to raw. A wave 2 raw converter is included with the units. At dos just type wav2raw teen2.wav teen2.raw. Once you've got the raw file you must put it in a library file containing all the sounds you want to use. sndlib.exe is also included with the units. To use it type sndlib teen2.lib + sound.raw sound, at the dos prompt. The second sound is the key witch will be used to load the sound from the file. The Procedure to load the SoundBlaster is very long so I put in a text file:INITSB.ZIP
const var begin FreeSound(Sound); PSound is a unit declared variable of type ^Tsoud, Tsound
is a record. Loadsound(Sound[1],'PLAY'); Click here to download the sound libraries, smix121.zip Any questions send them to pascalmisc@teentwo.8m.com 3. How to write a unit: To write a unit is very simple, first you must name all the procedures you are going to use and then you must write them out. EXAMPLE: Unit Teen2; Interface Uses Const Var Procedure Example(); Implementation Procedure Example(); Begin You can add ass many procedure ass you want. I advice that you add all the procedure that you use very often. Any questions send them to pascalmisc@teentwo.8m.com 4. How to execute dos commands in TP: It is quite simple to execute an dos command or external
program while running your program, but there are a few catches. Before and after running
the command you must type SWAPVECTORS; this swaps the contents of the SaveIntXX
pointers in the system with the current contents of the interrupt vectors. By doing this
you are preventing the program to use any of the interrupt's currently in use. EXAMPLE: {$M $4000,0,0 } var begin SwapVectors; if DosError <> 0 then{ Error? } The GetEnv('COMSPEC') commands determines the location of your command com and uses it to create a shell to run the command or program in. Any questions send them to pascalmisc@teentwo.8m.com 5. How to convert a string to text and back Turbo pascal has procedures to convert string into an number, VAL(string,number,number) and integer to string STR(number,string). Because these two are procedures that are quite hard to use because they do not send an obvious variable back. EXAMPLE: Uses Var Begin To convert real numbers to string it is advisable to ad a : with the amount of numbers to use and another : with the amount of numbers after the , . Any questions send them to pascalmisc@teentwo.8m.com 6. A function to convert letters to lower case. To understand how this works you must have a good knowledge of the ASCII table. The ASCII table contains all the characters a computer can recognize. Capital letter a is located at 56 and lower case a at 97, so all you have to do to convert a capital letter to lower case is to add 32 to it's ASCII value. EXAMPLE: Function LowerCase(let:char) : char; ORD determines where the character is located on the ASCII table. Any questions send them to pascalmisc@teentwo.8m.com 7. How to change the text cursor size. This procedure is based on assembler usage of bios interrupts to change stuff on the screen, if you understand this good for you but if you don't just copy it out and use it. To change the cursor size the values of the new size must be stored in the CH and CL registers. Once these values has been entered the 10H bios interrupt must be initialized. Giving the AH register the value of 01 you are requesting to set the cursor size. EXAMPLE: Procedure CursorSize(beg,en:byte); beg is where on the line the cursor will start and en where is will end, both must have a value between 1 and 16. To make the cursor disappear both must be 16, and to make it normal a gain both must have the value of 15. Any questions send them to pascalmisc@teentwo.8m.com 8.How to get and use command line parameters To determine how many parameters there are you use PARAMCOUNT. EXAMPLE: VAR Begin To determine the name of the program that is running use PARAMSTR(0); I want to get the whole command line and someone types "hello my name is" you will get a whole lot of blank spaces. So here is a nifty little function to get the whole command line for you. type CommandLines = string[127]; function CommandLine: CommandLines; type Any questions send them to pascalmisc@teentwo.8m.com 9.How to establish if a name refers to a directory or not All the file attributes can be established by using GETFATTR and GETFTIME. To find the files you use FINDFIRST and FINDNEXT. Once you've got the file you must assign it to a file variable ex. TEXT, FILE OF etc. When the file is assigned you use GETFATTR(file,attr) to get the file attributes. ATTR must be of type integer or word. If ATTR has a value of 16 it is a directory, but just to be sure it can be crossed checked with DIRECTORY wich is a variable that is declared in the dos unit and wich value changes when the name is found with findfirst or findnext. EXAMPLE: Uses Type Procedure FindFiles(var filese:fils; var count:word); Procedure FindFiles(var filese:fils; var count:word); begin var begin ATTR Values: If you want to get the Date and Time the file was last edited or created you must use GETFTIME. The time you get will be a integer and you must use UNPACKTIME to make it understandable. EXAMPLE: Const ............ Type ............ Var ............ GETFTIME(fi,fil[i].time); ............ Unpacktime(fil[i].time,tim); ............ Any questions send them to pascalmisc@teentwo.8m.com 10.How to find the files in a directory and sub directories The Pascal DOS unit has a function FSEARCH. The only problem with this function is that it stops once it has found the file. Usage FSEARCH(file,drive&directories); EXAMPLE: Uses Var Begin For a more comprehensive search you can use this in conjunction with FindFirst and FindNext. Any questions send them to pascalmisc@teentwo.8m.com 11.How to create arrays that are larger than 64 kilobytes. Break the array into two (types of) pieces: an array of row ptrs, and a set of rows on the heap. That is, replace type BigArrayType = array[0..Rows, 0..Cols] of DataType; with type BigArrayRow = array[0..Cols] of DataType; and replace any references to BigArray[Row, Col] with references to BigArray[Row]^[Col]. You will also have to allocate memory for your array by using NEW(BigArray); Once you have finished using your array you must dispose the memory you allocated so another application can use it. You do this by typing DISPOSE(BigArray); Any questions send them to pascalmisc@teentwo.8m.com |
|
This page is best viewed in 800x600x256. This page was last edited Tuesday, June 27, 2000 |