Skip to main content
gamedev.net
🔒 Locked

delphi pointer question

Started by Pillejunior Feb 2, 2004 at 9:19 AM 4 replies 350+ views
Original Post
Pillejunior
Pillejunior
Is this possible p : ^array[1..3] of integer; Because someone said to me it could but it giver a compilererror when ik try. thanx in advance
Alimonster
Alimonster
Yeah, you can do that -- just make it a type first:

type
TBlah = array[1..3] of Integer;
var
p: ^TBlah;

To be honest, I don''t know why it doesn''t let you do it directly though. Now, the next question is: what are you trying to do? There''s usually a more direct way than using pointers. If you''re wanting to dynamically allocate memory then just use a dynamic array instead of GetMem/New/FreeMem/Dispose, since it''s less error-prone.


[Fear me!]Visit my Delphi site or I''ll bite you! | DGDev Delphi Community
Pillejunior
Pillejunior
It''s for school, you had to do it this way. And now i know what i did wrong. Thank you very much. maybe we learn the others ways also. I hope
Pillejunior
Pillejunior
i have this type

tWijzer = ^tRecord;
tRecord = RECORD
kar : char;
next : tWijzer;
END;

en this procedure for making a linked list from a string but i am doing something wrong and can find it.

var i : integer;
begin
i := 0;
new(lijst);
lijst^.kar := edtString.text;
for i := 1 to length(edtString.text) do
begin
***HERE ITS WRONG how do i fill the next??
lijst^.next := new(lijst);
end
end;
Useless Hacker
Useless Hacker
I''m not sure I entirely understand your problem, but I think this maybe what you''re looking for:
var
j: Integer;
first, current: tWijzer;
begin
if (Length(edtString.text) > 0) then begin
New(first);
current := first;
current^.kar := edtString.text[1];
for j := 2 to Length(edtString.text) do begin
New(current^.next);
current := current^.next;
current^.kar := edtString.text[j];
end;
current^.next := nil;
end;
end;

first will point to the first item in the linked list.

P.S. It is conventional to name pointer types with an initial letter ''P'', i.e. type PThing = ^TThing;


[ DGDev -- The Delphi Games Development Community ] [ Help GameDev.net fight cancer ]
Pillejunior
Pillejunior
Thanx it works that was what i was looking for and also thanx for the naming tip. I will change the names.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.