Using Pointer : In Free pascal

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Pointer : In Free pascal

mokashe.ram
Hi Guys,

        I am using a pointer as shown below

        Locat_Pointer= ^ Locate
        Locate= Record
                 next:locat_pointer;
                  Code:word;

       How to assign USer input to pointer variable run time in free pascal Like Below
       Locate_Pointer^.code:=.....?

thanks
Sud
Reply | Threaded
Open this post in threaded view
|

Re: Using Pointer : In Free pascal

Mark Morgan Lloyd-5
mokashe.ram wrote:

> Hi Guys,
>
>         I am using a pointer as shown below
>
>         Locat_Pointer= ^ Locate
>         Locate= Record
>                  next:locat_pointer;
>                   Code:word;
>
>        How to assign USer input to pointer variable run time in free pascal
> Like Below
>        Locate_Pointer^.code:=.....?

Yes, that's about right, use something like

         Locate_Pointer^.code:= w;

where w is a word read in using something like the example code Marco
pointed you at a couple of days ago (if there's something you don't
understand in that I suggest raising it in that thread, rather than
starting another one).

Remember that you'll need to allocate each record with the next pointer
set to nil, and will also need to deallocate each one precisely once
when it's no longer needed. In practice most people would use a more
recent structure such as a TList, TStringList etc., what you've got
there is rather 1970s code and since then there's been consensus that
programs don't have to be written by reimplementing Lisp.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using Pointer : In Free pascal

Tomas Hajny-2
In reply to this post by mokashe.ram
On Mon, July 7, 2014 09:22, mokashe.ram wrote:


Hi Sud,

>         I am using a pointer as shown below
>
>         Locat_Pointer= ^ Locate
>         Locate= Record
>                  next:locat_pointer;
>                   Code:word;
>
>        How to assign USer input to pointer variable run time in free
> pascal
> Like Below
>        Locate_Pointer^.code:=.....?

If you ask about conversion of the input read using ReadLn into a string
variable to the word variable, then one option would be using procedure
System.Val (see http://www.freepascal.org/docs.var -> "Run-Time Library
(RTL) units reference manual" -> "System" -> "StringFunctions" -> "Val").

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal