Hi, I have a question. Is it possible to copy all contents from record to typed pointer which has same items? Example here:

program linked_list_queue;
type queue = ^myrecord;
    myrecord = record
        data: integer;
        otherdata: string;
        datadatadata: char;
        next: queue;
    end;
 
const head = nil;
    tail = nil;
 
procedure add(argument: myrecord); {adds data to queue}
var mypointer: queue;
begin
    new(mypointer);
    {Question: How can I move data from argument to mypointer? Is it possible?}
    {...}
end;

If yes, how can i do it?

Well. For a linked list you'd need to know where you're adding the item, so, you'd need to make a class so that add is applied to an item, so its added between the 2 items, and then you can handle deletion as well as moving, etc.

Well firstly Id recommend googling, delphi is not a new language, most of what you want will have been written at some point, as well as its often worth checking some of the units that come with delphi as sometimes you're inventing something you already have..

Try also looking at http://www.ibrtses.com/delphi/dllist.html which has the answer already done

I am a student and i need to write some functions or procedures to handle queue. One of the requirement is that it should be written in pascal (not any other language, not object pascal/delphi), so i can not use objects or classes. I know that makes things a lot more complicated, but this is because there will be simmilar tasks in exam. I will see if it would be possible to store data only in one variable in record.

Then your add needs to have the record to which its going to be added after, otherwise, how will you know where in the list it is?

You can use move, but you shouldnt need to, theres no reason to move the memory, just have the pointer reference, and add the new one so if (and this is totally ficticious) you had 3 items at 1000 and 2000 and 3000 and you added a 4th between the first and second, as long as the pointer knows the memory chunk is at 4000 for the next record you dont need to move it, and in doing so you waste cycles and create potential for bugs for no reason.

Absolutely agree. It was just an answer to his question, although I'd do it your way too.

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.