Is it possible to set a pointer that your pointing to? As in say i have a PChar called Bob and a Pointer called Harry, Harry points to Bob. Can i set Bob when all i have access to is Harry?
However, there is a difference between "Harry points to Bob" and "Harry points to the same location as Bob". In the first case Harry is a Pointer to a Pointer to a Char. Therefore you can modify the Bob-Pointer directly.
In the latter case Harry is just a pointer to a char. You can only modify the data directly, but not the location of the data.
_________________ Yeah!
Zuletzt geändert von Coolcat am Di Jan 25, 2011 14:49, insgesamt 1-mal geändert.
That sounds like a no rather than a yes. If i understand your post correctly then there isn't a way to set the actual PChar variable when you only have a pointer to the PChar variable(Well to allocate a PChar and have the original PChar variable point to it).
Worked out how to do what i want. I realised that a Pointer is just a number, so if Harry points to Bob's own data(bit that holds the Memory Address bob points to) then Harry can modify Bob completely.
Code:
var Harry : Pointer; Bob : PChar; begin Bob := '';
Harry := Addr(Pointer(Bob)); PChar(Pointer(Cardinal(Harry^))) := 'Hello';
MessageBox(0,Bob,Bob,0); //Bob = Hello
In case your wondering im working on a GUI and an Editor for it. Im making it so all of the GUI classes register there editable(And savable) properties(To a class inside themselves) so that the editor can then access a list of a GUI Element's editable properties(With pointers directly pointing to each property) and easily edit them without having to code special cases in the editor to handle each property of each class(Only have to code stuff to handle the variable types instead).
Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.