Solved

Accessing memory explicitly

Posted on 1998-09-20
1
152 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 61
Delphi selector screen 2 78
how to change, disabled button color FMX ? 1 32
Wincontrol not (correctly) drawn 15 37
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

774 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