You've just discovered the old record-property issue. This has been discussed many times on DUG with the conclusion that it's simply not possible... :( The "solution" is to turn your record into a class -- or to use C++ :)...
 
 
-Andreas
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Donovan J. Edye
Sent: Wednesday, 13 November 2002 14:09
To: Multiple recipients of list delphi
Subject: [DUG]: Accessing properties question...

G'Day,

I am curious about the following behaviour in Delphi 6.

  //Settings for TCP server
  TServerSettings = record
    Port : SmallInt;                    //Port server is listening on
  end;

  TSystemSettings = class(TObject)
  private
      FServerSettings : TServerSettings;
  protected
    function DoLoad(const AINIFile : TINIFile) : boolean; override;
    function DoSave(const AINIFile : TINIFile) : boolean; override;
  public
    property ServerSettings : TServerSettings read FServerSettings write FServerSettings;
  end;

var
  SystemSettings : TSystemSettings;

If I have the following statement

SystemSettings.ServerSettings.Port := 123;  //<-- Error - Left side cannot be assigned to

However the following:

with SystemSettings.ServerSettings do
begin
   Port := 123;  //Compiles with no problem
end;

Why is the above behaviour so?

If I make a small change and do the following: (ie not have record as a property)

  TSystemSettings = class(TObject)
  protected
    function DoLoad(const AINIFile : TINIFile) : boolean; override;
    function DoSave(const AINIFile : TINIFile) : boolean; override;
  public
    ServerSettings : TServerSettings;
  end;

then both of the above statements (using a with, single code line) compile without a problem.

-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [
www.edye.wattle.id.au]
Namadgi Systems [
www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [
http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------

Reply via email to