Hi, I would like to know how to port this code in Delphi

a : Word;
  b : ^Word;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
  b := @a;
  Inc(b^);
  //Display a
end;

To code in .NET, The problem is converting the pointer.

The Migrating Pointer Types section in the Codegear help gives this example however it does not explain it very well on how to use it.

var
  P: Pointer;
  I: Integer;
begin
  I := 5;
  P := @I;

could be converted to

var
  P: TObject;
  I: Integer;
begin
  I := 5;
  P := TObject(I);

Recommended Answers

All 3 Replies

Other than your initial question seems an overly weird thing to do.. I cant think of why you would ever find yourself in a position to do what that code does.. but .. we'll ignore that..

Everything in .net is an object, so by turning it to a generic "tobject" you have your effective pointer. Does that explain it better?

I would just like to know how to create and use a "pointer" in Delphi.NET. If you can give me an example that would be great

.net doesnt really have pointers.. You dont need them

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.