[DUG] O.o hmmm ok
Judd, Struan (eCargo)
struan.judd at ecargo.co.nz
Thu Jun 7 09:13:59 NZST 2007
Records are constructs with Value semantics whereas Objects have
Reference semantics.
This means that in the following code is the Assignment 1 and Assignment
2 are semantically identical:
Var a, b: record
name: String;
age: Integer;
end;
Begin
a.name := 'Me';
a.age := 39;
// Assignment 1
b := a;
// Assignment 2
b.name := a.name;
b.age := a.age;
End;
TTFN, Struan.
Nick wrote:
> 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
>
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with
> Subject: unsubscribe
DISCLAIMER: This electronic message together with any attachments is
confidential. If you are not the intended recipient, do not copy, disclose or
use the contents in any way. Please also advise us by return e-mail that you
have received the message and then please destroy. Carter Holt Harvey is not
responsible for any changes made to this message and / or any attachments after
sending by Carter Holt Harvey. We use virus scanning software but exclude all
liability for viruses or anything similar in this email or any attachment.
More information about the Delphi
mailing list