Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Do Mär 28, 2024 14:45

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Setting a pointer your pointing to
BeitragVerfasst: Di Jan 25, 2011 14:19 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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?

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Jan 25, 2011 14:35 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Yes.

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! :mrgreen:


Zuletzt geändert von Coolcat am Di Jan 25, 2011 14:49, insgesamt 1-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Jan 25, 2011 14:43 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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).

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Jan 25, 2011 14:51 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Zitat:
That sounds like a no rather than a yes.

Sorry, "yes" in the first case and "no" in the second. I added a break above to make it more clear.

Edit: Note that a PChar variable is already a pointer to a Char.

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mi Jan 26, 2011 00:39 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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).

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 8 Gäste


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.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.070s | 17 Queries | GZIP : On ]