DOCUMENTATION

key windows 7

    FAQ - Frequent Questions and     nbsp; 10hadv
 

 10h advice to the programmer On TP

From: "Victor B. Wagner" <> Subj: And whether you know that... (ver 2) .10H Advice to the programmer on TP Organization: Agroecological problems Center About one month back I already sent the first The version of this text in a teleconference. Then Advice was 8. Now their number has grown twice. But As the first advice have passed during a season years Holidays, I just in case repeat also them.

Work with Turbo Pascal

I invite all who makes small opening During work with Turbo Pascal to follow mine To example and to write about them not waiting, while Somebody desperately завопит: "HE-E-ELP!!!" Suddenly To whom приго-дится. And whether you know? A little (10h) Advice to the programmer on Turbo Pascal >$0001) And whether know You, that procedure Rename in Turbo Pascal поз-воляет To move files from one catalogue to another (The truth within the limits of one disk)? >$0002) And know Whether you, that in spite of that affirms in Help, from Programs on TP can be opened more than 16 files (in Limit - it is so much, how many it is written in command FILES CONFIG.SYS). Here so: Procedure SetMaxFiles (Count:Word); assembler; asm Mov AH, 67H MOV BX, Count Int 21H end; After that cause SetMaxFiles (40) and 40 Files (including, the truth 5 standard) in yours The order. >$0003) and whether you know, that for that, To cause from yours прог-раммы another, It is absolutely not obligatory to set the instruction $M and To limit memory of your program during the moment Compilations. Available in module Memory Turbo Vision Procedure SetMemTop поз-воляет to give affiliated To process all free dynamic.

Here So SetMemTop (HeapPtr); {we Give memory} Exec (GetEnv (' COMSPEC '), "); {In The given case it is caused DOSShell} SetMemTop (HeapEnd); {It is taken away It back} >$0004) And whether is known by you (in my opinion, it Peter Nor-does not know even tone), that starting from Your program DOSShell you can quite leave in Environment the empty seat suffices for work Complex BAT-files. The decision lays on a surface: Let пере-менная EnvSize:Integer contains the size Root Environment (whence you it will take - yours Business. It is possible to take advantage мо-дулем TPEnv from Archive BONUS in TurboProfessional, it is possible to set simply Constant it is more. Further we do here so Str (EnvSize, tmpString); Exec (GetEnv (' COMSPEC '), '/E: ' + tmpString); Why it Norton, then has not made if not Wolves, I not I know. >$0005) and whether you know, that to the address of object (Typified кон-станты or procedures) in On TP it is possible for the program very simply - лучить it Displacement in an EXE-file Here so: Var Self:File; HdrSize:Word; Const SomeThing:record.... end = (....); begin Assign (Self, PAramStr (0)); {we Shall open Own file} Reset (Self, 1); Seek (Self, 8); {we consider the size Its heading (a word on displacement 8)} BlockRead (Self, HdrSize, 2); Offset: = Ofs (SomeThing) + LongInt ((Seg (SomeThing)-PrefixSeg-$ 10+HdrSize)) *16; {And here The formula for calculation of displacement. Now it is possible запи-сывать the changed value of constant SomeThing, And at following start of the program at it There will be such impression, that and was It is conceived at compilation} Seek (Self, Offset); BlockWrite (Self, Settings, Size); Close (Self); >$0006) And whether you know

Why in the previous example was Transformation of types to the formula? It any more DOS, it Pure Turbo Pascal. Contrary to statements Documentation of calculation in integers of type Integer And Word are done without reduction type Longint. Therefore Not having made this reduction, we would risk As soon as the size of our file will exceed 64 To, or To receive Range Check Error, or, at compilation with R- To receive not that value what is necessary, and the rest from Its divisions on 65536. The given thing (it not a bug, and Means of increase of efficiency, to сожале-нию Badly documentary) very often serves Source of difficultly caught mistakes. >$0007) and You know, that the address which gives out Turbo Pascal at To mistake of time of performance, it is calculated on To formula Ptr (Seg (ErrorPoint)-PrefixSeg-$ 10, Ofs (ErrorPoint)) >$0008) And you Know that in DOS there are functions of transformation Lines in the top and bottom registers, and if in CONFIG.SYS Costs COUNTRY=007, they correctly work with Russian Letters. For example: Function Upcase (C:Char):Char; assembler; asm mov AX, 6520H mov DL, C int 21H mov AL, DL end; And it is possible to translate for one call In the top register the whole line String or PChar. It Minorant functions 21H and 22H the same function 65H the Variant for String I shall result, and for PChar write - it easier. Procedure UpString (var S:String); assembler; asm Push DS LDS BX, S XOR CX, CX MOV CL, [BX]; Length Lines in CX INC BX MOV DX, BX; DS:DX-the index on the first Symbol MOV AX, 6521H INT 21H POP DS end; For a minorant function 22H The index on ASCIIZ a line is transferred in the same DS:DX >$0009) whether Know you how to force your program At occurrence of a mistake on a disk or the printer To give out standard досовское "Abort,Retry,Ignore", Instead of to take off on Runtime Error...? (It does not concern Programs using Turbo Vision, Turbo Professional or Something similar) Is trivial: SetIntVec ($24, SaveInt24) Forces your program to use Standard DOS-овским обработчиком mistakes instead of Standard паскалевского. >$000A) And whether you know As in a graphic mode to deduce by means of Writeln The text on a color background? (color it is considered a background Nonzero color. To that you there have appointed zero Color - your business) First - what for?) because in Modes the sanction more 640х200 Writeln uses 14 And 16 bit fonts which are more beautiful than 8-bit, used by default OutText'ом. Because to deduce numbers Writeln'ом it is more convenient Because told about Writeln concerns and to Readln'у, And to it the analogue in the schedule is not present. Secondly - as? Let's assume, that you use module CRT, for about What color there can be a speech without it. Naturally in the beginning of the program you have put DirectVideo: = False, differently you in general any conclusion not Will see also a conclusion goes through 10 interruption. In Graphic mode parameter attribute, which in Text mode works as color of the text and a background It is treated as color of the text. But if the senior of bats It is equal 1 (Color Or $80), color of each point XOR-?O with that That was on this place. Therefore we do so {Let Variables TxColor and BkColor contain color of the text and color Background accordingly, and line S - that is necessary To deduce} TextAttr: = BkColor; X: = WhereX; Y: = WhereY; For i: = 1 to Length (S) do Write (#219); {Chr (219) = ' ђ '} {It can be made for one call Functions BIOS, as one of its parameters - number Recurrences, but we shall not optimize to the detriment of Clearness} GotoXY (X, Y); TextAttr: = $ 80 or (txColor xor BkColor); Writeln (S); In Case Readln it is a little bit more complex, as it is possible In advance to clear a field of input, and then will appropriate TextAttr that it is necessary and to cause Readln, but Experiment after that with a key BackSpace. It is better to get into the initial text of module Crt and To enter corresponding things it is direct in the driver Text file. The author has somehow made it and Module VCrt can be found on Moscow BBS or on mailserv@sl.semsk.su >$000B) And whether know you how to check up, Whether your program on the screen or its conclusion writes was Somewhere it is renominated? Here so: Function Redirected (var F:Text):Boolean; inline ($5F {POP DI} / $07 {POP ES} / $26 / $ 8B / $ 1D {MOV BX, ES: [DI]} / $B8 / $ 00 / $ 44 {MOV AX, 4400} / $CD / $ 21 {INT 21} / $F7 / $ C2 / $ 80 / $ 00 {TEST DX, 0080} / $74 / $ 0A {JZ @@ 1} / $F7 / $ C2 / $ 03 / $ 00 {TEST DX, 0003} / $74 / $ 04 {JZ @@ 1} / $B0 / $ 00 {MOV AL, 00} / $EB / $ 02 {JMP 011C} / $B0 / $ 01); {@@ 1:MOV AL, 01} {@@ 2:} It is caused Accordingly Redirected (Input) or Redirected (Output) also gives out True if input or output of the program goes not with Devices CON. It is impossible to use this функцей If For a file with which it works, was Procedure AssignCrt or AssignDevice (attention is executed Code of initialization of module CRT the first of two вышеупомянутых procedures causes both for Input and for Output) >$000C) And whether know you how to combine in one To the program use of module CRT and standard Conclusion? Only not how it is done by Figurnov in To the book "IBM PC for яюыічютр=хы " (Program CRCList) All is much easier - get Text file, for example F also do to it Assign (F, "); Rewrite (f); After that all that is written to this file, Goes on стандатный conclusion DOS. It is desirable the truth To take advantage of function Redirected from previous Advice and to add next five lines: if not Redirected (F) then begin AssignCRT (F); Rewrite (F); end; Then a conclusion on The screen will go through CRT, nevertheless it it is possible Will renominate. Attention - function Redirected It is caused for the OPEN file standard Input-output. >$000D) and whether you know the idle time Way to force the program on TP to publish squeak? Write (^G); >$000E) And you know, that having opened File variable it is possible to receive a name easily File? (I suspect, that know - in fact it does Built in debugger Turbo Pascal, but how?) FileName: = StrPas (PChar (@TextRec (F) .Name)) (function StrPAs is used From module Strings in TP 7.0. Who works in 6.0 and less, Can replace it on Asciiz2Str from TurboProfessional. If File not text, in order to prevent mistake Invalid type cast use FileRec instead of TextRec (both that and another It is described in module DOS)) >$000F)

Turbo Professiona it is not compiled

Whether and you know why Turbo Professiona versions 5.11 or about that and Object Professional Early versions it is not compiled under the seventh паскалем? The matter is that during the moment of their release паскаля 7 yet was not and consequently Turbo Professional thinks, That at all versions except for 6 structure dynamic Memories same, as well as in 5 (for 4 and 5.5 it Really so) Add in file TPDEFINE.INC Next three lines {$IFDEF Ver70} {$DEFINE Heap6} {$ENDIF} If You have version 5.05 or earlier, which and 6-th that паскаля does not know, look to itself Something поновее. Vitus Wagner Origin:SoftWeyr >$0010) And Whether you know how to hide the text cursor, if You use module CRT for creation of the menu, etc. If you do not have opportunity directly to address to Functions of change of the sizes of cursor BIOS (you not Know its interface, you do not wish to use The built in assembler, etc.) it is possible to tire out The cursor in 26 line of the screen, which, as is known on The screen it is not visible. It is standard reception at work On the assembler. But module CRT possesses harmful Habit to not allow to position the cursor For limits of a window. (by default a window - Window (1,1,80,25); It is necessary to deceive it - in the beginning of the program increase Value of variable WindMax on 256 (number of a line It is stored in the senior байте). After that GotoXY (1,26) Will clean the cursor from the screen.