Recent

Author Topic: Question on "absolute"  (Read 595 times)

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 87
Question on "absolute"
« on: October 18, 2024, 09:38:16 pm »
Code: Text  [Select][+][-]
  1. I understand the absolute concept. My question is
  2. if I make a local variable "X" absolute to a global variable "XX"
  3. as in the code below, am I "technically" correct in saying that for
  4. all intents and purposes that my local variable is then
  5. actually made into a global variable?
  6. ie:  Pressing Button1 then Button2 gives me 102


Code: Pascal  [Select][+][-]
  1. var
  2.   Form1: TForm1;
  3.   xx: integer;
  4. implementation {$R *.lfm} { TForm1 }
  5.  
  6. procedure TForm1.Button1Click(Sender: TObject);
  7. var
  8.   x: integer absolute xx;
  9. begin
  10.   x:=102;
  11. end;
  12.  
  13. procedure TForm1.Button2Click(Sender: TObject);
  14. var
  15.   y: integer absolute xx;
  16. begin
  17.   form1.Caption := ' y = '+IntToStr(y)+' ';
  18. end;                  
« Last Edit: October 18, 2024, 10:05:12 pm by Ten_Mile_Hike »
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

Fibonacci

  • Hero Member
  • *****
  • Posts: 602
  • Internal Error Hunter
Re: Question on "absolute"
« Reply #1 on: October 18, 2024, 09:58:05 pm »
Yes

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: Question on "absolute"
« Reply #2 on: October 19, 2024, 11:10:05 pm »
Keep in mind, it's also a quick way to cast over items like a WORD where you have a Byte type that can point to a WORD type.
this at lest gets the low bound without using LO.

also, I think you can even offset the address to get the high bound?

So this allows you to have two variables pointing to a single variable of different type.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. Type
  3.   TR = Record B:Array[0..3] of Byte End;
  4. Var
  5.   W:DWORD;
  6.   R :TR absolute W;
  7. begin
  8.    WIth R do
  9.    Begin
  10.     b[0]:=  192;
  11.     b[1]:=   168;
  12.     B[2]:=  Random(10);
  13.     B[3]:=  Random(255);
  14.    End;
  15. end;                        
  16.  

Something like that! :o
« Last Edit: October 19, 2024, 11:22:41 pm by jamie »
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 16168
  • Censorship about opinions does not belong here.
Re: Question on "absolute"
« Reply #3 on: October 19, 2024, 11:27:30 pm »
We have variant records for that. The use of absolute is usually not recommended and it is easy to make mistakes in its use.
Code: Pascal  [Select][+][-]
  1. Type
  2.   TR = Record
  3.          case boolean of
  4.          false:(B:Array[0..3] of Byte;);
  5.          true :(W:dword;);
  6.       end;
  7. Var
  8.   R :TR;
  9. begin
  10.    WIth R do
  11.    Begin
  12.     b[0]:=  192;
  13.     b[1]:=   168;
  14.     B[2]:=  Random(10);
  15.     B[3]:=  Random(255);
  16.    End;
  17. end.
                     
« Last Edit: October 20, 2024, 08:49:41 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

d2010

  • Jr. Member
  • **
  • Posts: 62
Re: Question on "absolute"
« Reply #4 on: October 22, 2024, 08:51:25 am »
We have variant records for that. The use of absolute is usually not recommended and it is easy to make mistakes in its use.
Yes i think the "absolute of var" generate too much crash, inside run-time (even
TurboPascal  for windows3.1", the "absolute" is very worst.
 Delphi5 not more used?

 

TinyPortal © 2005-2018