AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

array of pointers

Ein Thema von sk.Silvia · begonnen am 24. Jun 2006 · letzter Beitrag vom 24. Jun 2006
Antwort Antwort
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#1

array of pointers

  Alt 24. Jun 2006, 13:57
hi there, i want to make an array of pointers as follows

Delphi-Quellcode:
type pointer_array=array[0..50] of pointer;
var Pointers:pointer_array;

      procedure HandleInput(Message1:string; var ExportVar:real);
          begin
          inc(Step_input);
          Pointers[Step_input]:=ExportVar; //DONT WORK
          Pointers[Step_input]:=^ExportVar; //DONT WORK
          ^Pointers[Step_input]:=^ExportVar; //DONT WORK
          //unimportant commands here
          end;
what i want to do, is to store a pointer to each variable imported to procedure
(HandleInput('0', CXC)-> ExportVar=CXC -> i will store a pointer to CXC)
how to do it?

thanks
  Mit Zitat antworten Zitat
Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#2

Re: array of pointers

  Alt 24. Jun 2006, 14:01
You need the address of a variable, which you'll store in a Pointer. To get the Address of a Variable, use the @-Operator.
In your case it would be then:
Pointers[Step_input] := @ExportVar greetz
Mike
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#3

Re: array of pointers

  Alt 24. Jun 2006, 14:09
great)

and now when i will to get the value of the variable on what it shows

Delphi-Quellcode:
ExportVar:=10;
Pointers[Step_input] := @ExportVar;
how do i get the value 10 from Pointers[Step_input]
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#4

Re: array of pointers

  Alt 24. Jun 2006, 14:19
Delphi-Quellcode:
procedure HandleInput(Message1:string; var ExportVar:real);
var i1:integer;
    adr:real;
          begin
          Pointers[Step_input]:=@ExportVar;
          @adr:=Pointers[i1];
          
          ShowMessage(FloatToStr(adr));
          
          end;
i tried to make this, but it isnt working (@adr:=Pointers[i1]; - cannot assign left side)
  Mit Zitat antworten Zitat
Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#5

Re: array of pointers

  Alt 24. Jun 2006, 14:19
You have to dereference the Pointer. This usually works like this:
IntegerValue := PointerToInteger^ But, since you're not using typed Pointers, you have to tell, that this is an integer, so a simle cast is enaugh:
IntegerValue := Integer(Pointers[Step_input]^) btw, code is always easier to read, if you use typed Pointers (means: ^integer instead of Pointer), so if you intend to store only one Datatype in those Pointers, youse typed Pointers

greetz
Mike
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#6

Re: array of pointers

  Alt 24. Jun 2006, 14:22
Dankeshon, its working fine, thanks
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#7

Re: array of pointers

  Alt 24. Jun 2006, 15:02
well but there is a problem

http://www.politea.sk/employ/elvenone/cccc.jpg

the adress of ExportVar and Ratio is the same, thats OK
but why is the value of tmpr not same as the value of Ratio=ExportVar (the value of tmpr is 0 and the value of Ratio is 1,58 )?
  Mit Zitat antworten Zitat
Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#8

Re: array of pointers

  Alt 24. Jun 2006, 18:11
Zitat von sk.Silvia:
the adress of ExportVar and Ratio is the same, thats OK
but why is the value of tmpr not same as the value of Ratio=ExportVar (the value of tmpr is 0 and the value of Ratio is 1,58 )?
On the left side of your Code you see a fiew blue points. In some lines these blue points are missing. This means, that this line of code has not been compiled, most times, because it was unnecessary. Here you're propably not using the variable temp anymore after the assignment, so it is unnecessary to execute that operation.
As short answer: the variable temp has the value 0, because the value has not been assigned for optimation reasons.
There are two ways to avoid this:
  1. you do something with the variable after the assignment. A ShowMessage(FloatToStr(temp)), for example.
  2. you disable compiler Optimation for the necessary lines of code, by using the {$O+/-}-Flags.

greetz
Mike
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:16 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz