Re:Why won't this code work?
You can do a couple of things,
if it was a Typed pointer you could use the Inc(P) on because the compiler
would know the referrence destenation size , how ever, since you are not doing
so you can type case it..
Dword(Ptr) := Dword(Ptr)+Sizeof(What ever);
--
a more elligent way to do this is...
type MyArray = Array[0..0] of MyType;
Var
MyVar:^Myarray;
begin
MyVar := @Buffer;
X:Integer;
Begin
X := 0;
If MyVar[X] = ????? Then Inc(X) ect....
End;
--
Here you have created an Pointer To an array that the compiler will auto reference
by pointer using the X as the offset value..
I think this is more of what your looking for..
Quote
Ron Davis wrote:
> You wouldn't think it by this question, but I have been writing C and assembly
> for 15 years, and Delphi for 4 or so. Luckily I have largely avoided pointers in
> Delphi until now. My syntax below may not be exactly correct, but I made it up
> on the fly.
> Why won't this work?:
> type MyType
> blah
> blah
> end;
> procedure MyProc;
> var
> Ptr :Pointer;
> begin
> Ptr:=@AddressOfBuffer;
> While (SomethingIsTrue) do
> begin
> DoSomethingWith(Ptr);
> Ptr:=Ptr+SizeOf(MyType); //This is the problem
> end;
> end;
> I guess my question is really; How do you add a number to a pointer? You can
> Inc() the pointer, but can't add to it. I know I can make a type that is a
> pointer to MyType and Inc() that, but that will not work for me in this case.
> --
> Thanks,
> Ron Davis
> c...@oaktree.net