### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [Solved] pointers  (Read 1189 times)

#### Ten_Mile_Hike

• Jr. Member
• Posts: 63
##### [Solved] pointers
« on: May 20, 2024, 12:13:37 am »
I know the BASICS of pointers, but I'm just playing around ---and wondered;
if the value of memory location of A below is 341576016 how can I display that in pascal?
I've tried ABSOLUTE and did get a  7 digit value back, but I don't know if that is valid.
If not in pascal, how about inline ASM?

AGAIN...I'm just goofing around. Not trying to program anything

Thanks

Code: Pascal  [Select][+][-]
1. var
2.   A:Integer;
3.   A_Ptr:PInteger;
4. begin
5.   A:=77;
6.   A_PTR:=@A;
7.

« Last Edit: May 22, 2024, 06:52:08 am by Ten_Mile_Hike »

#### jamie

• Hero Member
• Posts: 6312
##### Re: pointers
« Reply #1 on: May 20, 2024, 12:26:59 am »
Writeln(IntToStr(A_Ptr^));
The only true wisdom is knowing you know nothing

#### Martin_fr

• Hero Member
• Posts: 10010
• Debugger - SynEdit - and more
##### Re: pointers
« Reply #2 on: May 20, 2024, 01:46:35 pm »
The actual address stored in the pointer:

Code: Pascal  [Select][+][-]
1. writeln(IntToStr(PtrUInt(A_Ptr)));

Or "IntToHex" if you prefer.

PtrUInt will be QWord or Cardinal (or ...) depending on what bitness you compile for. So you can always use this to cast the pointer into a number.

#### TRon

• Hero Member
• Posts: 2801
##### Re: pointers
« Reply #3 on: May 20, 2024, 01:53:24 pm »
In addition, and in case not wanting to rely on sysutils:
Code: Pascal  [Select][+][-]
1.   WriteLn(HexStr(A_Ptr));
2.

#### gidesa

• Jr. Member
• Posts: 87
##### Re: pointers
« Reply #4 on: May 20, 2024, 02:21:54 pm »
There is also format() with P type argument,
see: https://www.freepascal.org/docs-html/rtl/sysutils/format.html

Code: Pascal  [Select][+][-]
1. uses SysUtils;
2. .............
3. Writeln(Format('%P',[A_ptr]));
4.
« Last Edit: May 20, 2024, 02:36:58 pm by gidesa »

• Hero Member
• Posts: 14850
• Censorship about opinions does not belong here.
##### Re: pointers
« Reply #5 on: May 20, 2024, 03:19:01 pm »
Format is overkill:
Code: Pascal  [Select][+][-]
1. var
2.   b:PtrUint = 12345;
3. begin
4.   writeln(b);            // value
5.   writeln(PtrUint(@b));  // address
6. end.
Remember the Medway disaster..

#### Ten_Mile_Hike

• Jr. Member
• Posts: 63
##### Re: [Solved] pointers
« Reply #6 on: May 22, 2024, 06:53:39 am »
Thank you everyone for your responses.
I greatly appreciate it.