Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-07

Using Pointer : In Free pascal

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd
to mokashe.ram
mokashe.ram wrote 12 lines
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]

Reply by email

Tomas Hajny
to mokashe.ram: I am using a pointer as shown below Locat_Pointer= ^ Locate Locate= Record…

On Mon, July 7, 2014 09:22, mokashe.ram wrote:

Hi Sud,

Show quoted text 11 lines
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

Reply by email