Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Borland > Re: Some miscel...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 1029 of 1118
Post > Topic >>

Re: Some miscellaneous pascal esoterica

by "Matt Claessen" <nospam@[EMAIL PROTECTED] > May 23, 2007 at 10:56 PM

"HubbleBubble" <phil_simmons@[EMAIL PROTECTED]
> wrote in message 
news:1179916962.034090.22760@[EMAIL PROTECTED]
> Hi All,
>
> One thing that I can't figure out is the text vs binary thing.
> As you know in dos a file handle is just an integer. Presumably this
> points to an internal record of type file or does the user need to
> optionally supply a pointer to a file structure?. Is the text record
> structure part of dos or is it handled entirely by pascal?. If it is
> dos how might I tell dos which type of file I want?
>
The difference is made in the filetype
Textfiles are type TEXT in BP7 (or TextFile in Delphi)
Binary files are File of Byte.

You can read a number of bytes and then convert them to any other type by 
using one of the following tricks:

- dereference a pointer into a variable of the other type, this will work 
with any variable, even large records.
- use a variant record, like

s = record
    case Byte of
      0: ( sa  : array [1..4] of Byte );
      1: ( res : Single );
    end;

var u: s;

You can now read the four bytes from your binary file, and set them like 
u.sa[1]:=byte1; etc., and then access the single precision real with u.res

Turbo Pascal used this trick to access the registers, either 8 bit or 16
bit 
wide.

type
  Registers = record
     case Integer of
     0: (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: Word);
     1: (AL, AH, BL, BH, CL, CH, DL, DH: Byte);
   end;

HTH, Matt
 




 3 Posts in Topic:
Some miscellaneous pascal esoterica
HubbleBubble <phil_sim  2007-05-23 03:42:42 
Re: Some miscellaneous pascal esoterica
"Matt Claessen"  2007-05-23 22:56:25 
Re: Some miscellaneous pascal esoterica
Marco van de Voort <ma  2007-05-24 21:17:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:33:52 CDT 2008.