Solved

Accessing memory explicitly

Posted on 1998-09-20
1
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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