Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Accessing memory explicitly

Posted on 1998-09-20
1
Medium Priority
?
162 Views
Last Modified: 2010-04-06
[Note: I am using Delphi 2.0]

If XPtr and YPtr are pointer variables and Offset is an integer/word/longint/etc., is it legal to do the following?

XPtr := YPtr + Offset;

(in case you're curious, in my application XPtr is a pointer to a bitmap and I want to get the memory location Offset bytes from the beginning)

In Delphi 2, I noticed that the seg and ofs functions are obsolete.

I have not tried compiling the unit that uses the XPtr := YPtr + Offset yet, but I assume it is legal.  If it is, would someone confirm this, and if it is not, please tell me how to do it.  Thanks.




0
Comment
Question by:scrapdog
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 0 total points
ID: 1340339
scrapdog,

it is legal. But be careful with the types!!!

var XPtr,YPtr : ^integer;
    Offset    : integer;

inc(XPtr,integer(YPtr)+Offset);  
// don't do it this way, because Delphi then thinks that you mean:
// inc(XPtr^,integer(YPtr)+Offset);

// do it this way...
XPtr:=pointer(integer(YPtr)+Offset);

Regards, Madshi.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question