From: gvision@ntlworld.com   
      
   "Bill Leary" wrote in message   
   news:I_qdnVyLKtdghZ_fRVn-pw@giganews.com...   
   > "RadSurfer" wrote in message   
   > news:1107412767.319036.77740@f14g2000cwb.googlegroups.com...   
   > > OK! TP 5.5 appears to be somewhat like Qbasic and VBforDos...   
   > > to use GetMem, I 1st declare a "pointer" (whatever that really means),   
   > >   
   > > BlockPtr: pointer;   
   > >   
   > > getmem(BlockPtr, AmountRam);   
   > >   
   > > What exactly is this "pointer" ? A far* that is 24-some-bits, or   
   > > what?   
      
   First off, you should avoid untyped pointers as much as possible. If you   
   have some type declared - lets call it TSomeThing - and you are using   
   pointers to access instances of it (that is, normally instances allocated   
   from the heap), then you also define a "typed pointer" for it:   
      
   type   
    PSomeThing = ^TSomeThing;   
    TSomeThing = record   
    Whatever: Integer;   
    BigNose: String;   
    end;   
      
   Note that there are two type declarations here - PSomeThing and TSomeThing.   
   The same thing can be used for predefined types:   
      
   type   
    PInteger = ^Integer;   
    PWord = ^Word;   
    ..etc   
      
   A pointer in TP is always a far (16:16) pointer. That is, a 16-bit segment   
   and 16-bit offset.   
      
   Secondly, always use "New" and "Dispose" (not GetMem and FreeMem) to alloced   
   and release "typed memory":   
      
   var   
    P: PSomeThing;   
   begin   
    New(P);   
    ....   
    Dispose(P);   
   end;   
      
   > > Is it possible to convert/treat this "pointer" as a purely integer   
   > > value ?   
      
   You can convert it to Longint, since it is the same size, but this strongly   
   discouraged since the only part of a pointer that can rationaly be   
   manipulated is the offset part. You can declare the following "special"   
   type-cast type and use that to perform pointer manipilation:   
      
   type   
    PtrRec = record   
    Ofs: Word;   
    Seg: Word;   
    end;   
      
   Now if "P" is an instance of some pointer type you can do the following:   
      
    Inc(PtrRec(P).Ofs, X);   
      
   Where "X" is an ordinal value.   
      
   Note that in TP7/BP7 you can also do the following:   
      
    Inc(P, X);   
    Dec(P, X);   
      
   Where "P" is still a typed-pointer instance. In this case, The value of X   
   will multiplied by SizeOf(P^) before being added to (the offset part of) P.   
   I don't know if TP5.5 can do this though (TP5.5 is VERY old).   
      
   > You're not supposed to ever mess with a Pascal pointer other than to   
   > assign to it. If the C program you're translating does a lot of pointer   
   math,   
   > things like p = p + 5; with the assumption that 'p' will be advanced by 5   
   > elements of what 'p' points to, or p = p + (sizeof)thing, or even p++,   
   you're   
   > probably in deep trouble.   
      
   Not deep trouble (at least not in TP7), but he would be better to convert it   
   to an array and manipulate the array index variable.   
      
   > > Is type-casting ever done in TPascal ?   
      
   Yes, but when you know the language better, you will try to avoid them like   
   the plague because they are ofter the source hard-to-find run-time errors.   
   In short, pointer manipulation and type-casting are both major causes of   
   errors, and are two reasons why C programs never work properly ;-)   
      
   > > Quite the challenge me thinks.... :-)   
      
   Not really. Your big challenge is to get you head around strong-typing. Note   
   that this is the way new mainstraim languages are going - C# and Java are   
   both strongly typed. Pascal has had it since the early 70's. Once the penny   
   drops, you'll wonder how you ever managed without it.   
      
   --   
   Jay   
      
   Author of Graphic Vision   
   http://homepage.ntlworld.com/gvision/   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|