[DUG] O.o hmmm ok

Nick nick at salehoo.com
Thu Jun 7 09:01:45 NZST 2007


Got something weird here - weird because I probably don't understand it 
properly but it caused me a bit of delay...
Simplified, I had a global array of records, during my procedure I would 
do something like this

PRec := MyArrayofPRec[0];
PRec.name := 'Hi';

Now for some reason I was expecting MyArrayOfPRec[0].name to be now 'Hi' 
as well, but it's not.

Here is an example that I whipped up just now which lead me to expect this.

type
  TMyRec = Record
    name : string;
  end;


var
  Form1: TForm1;
  TTH : TMyRec;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TTH.name := 'BoB';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  t : TMemo;
  b : TMyRec;
begin
  t := Memo1;
  t.lines.add('hi');

  b := TTH;
  b.name := 'Smile';
  t.lines.add(TTH.name);
end;

Now in this example when it's ran and button 1 is clicked - Hi is added 
to the Memo1 and Bob is added.
So why can I assign Memo1 to T and all actions done to T are done to 
Memo1, but the same isn't with the Record.
Is it because Record isn't from TObject?
I guess it's like
var
    a,b : integer;
begin
    a := 1;
    b := a;
    b := 10; //a still = 1 which is what I would expect
end;

so is it because TMemo is an Object and the record and a,b above are 
just variables?

O.o
Thanks





More information about the Delphi mailing list