Solved

Pointers in Delphi 32

Posted on 1998-01-02
2
922 Views
Last Modified: 2008-02-26
My problem is, I have to increment a pointer.
    In old 16 bit code, I does it by use
   p := ptr(seg(p^),ofs(p^) + n);
    but this is not longer possible in delphi 32. So how can I do the
same stuff in 32bit?
    Here is some dummy code to make my problem more understandable...
    Type
   Rec = record
      size: integer;
      data: array[0..0] of byte;
   end;
   prec = ^rec;
   procedure readmorerecs;
   var
  p : pointer;
  numberofrec: integer;
   begin
  filestream := tfilestream.create('somefile',fmopenread);
  getmem(p,filestream.size);
  filestream.read(numberofrec,sizeof(integer));
  filestream.read(p^,filestream.size);
  interpretrec(p,numberofrec);
  filestream.free;
   end;
   procedure interpretrecs(var p; numberofrec: integer);
   var
  myrec: prec;
   begin
  myrec := @p;
  while numberofrec > 0 do
  with myrec^ do
  begin
   dosomething with myrec
   // not possible in 32 bit
   myrec := Ptr(Seg(myrec^),Ofs(myrec^)+Size);
   dec(numberofrec);
  end;
   end; *)

--
info@cpfreiburg.de
0
Comment
Question by:karlhfreiburg
2 Comments
 
LVL 1

Accepted Solution

by:
hustch earned 100 total points
ID: 1355110
In Delphi 32, you don't use the segment any more, the 32-bit pointer is an offset.
You can add Size to your pointer directly. If the Compiler won't let you do it with a pointer of type prec, you can typecast it to type PChar (myrec := prec(PChar(myrec)+size);)
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1355111
Maybe Size here is meant to be SizeOf(Rec)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now