Umm.  Hate to state the obvious, but ...

Why not make an attribute FTest_Null and a readonly property TestNull on
your object?

Something like:

unit X;

interface

  TMyClass = class(TObject)
  private
    FTest_Null: Boolean;
    FValue: integer;
  public
    property TestNull: Boolean read FTest_Null;
    constructor Create(AValue :Integer);
  end;

var
   MyClass :TMyClass;

implementation

constructor TMyClass.Create(AValue :Integer);
begin
  inherited Create;
  FTest_Null := (AValue = 0);
end;

end;

Some discipline will be required (making sure you use .TestNull rather than
.FTest_Null for method implementations for the class.)


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of leigh
Sent: Saturday, 6 May 2000 14:37
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Declare const object


Dear Aaron,

This method is currently I use. But I am not happy about that. Because I
want that variable to be logical const, no one should modify it. I want
compiler automatic tell me it is an error if in my code I try to modify the
value.

Thanks any way.

Best Regards
leigh

----- Original Message -----
From: Aaron Scott-Boddendijk <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Sent: Saturday, May 06, 2000 2:05 PM
Subject: Re: [DUG]: Declare const object


> You can't declare it like that I'm afraid...
>
> the best you could probably do would be
>
> unit X;
>
> interface
>
>   TMyClass = class(TObject)
>   public
>      AValue :Integer;
>      constructor Create(AValue :Integer);
>   end;
>
> var
>    MyClass :TMyClass;
>
> implementation
>
> constructor TMyClass.Create(AValue :Integer);
> begin
>    inherited Create;
>    Self.AValue := AValue;
> end;
>
> initialization
>    MyClass := TMYClass.Create(0);
> finalization
>    MyClass.Free;
> end;
>
> I tend towards data-driven code a lot and rather than consts I use file,
registry,
> resource, db or remote sources for the initialisation values of my
structures... Of
> course sometimes you just want a const ;)
>
> --
> Aaron@home
>
>
> --------------------------------------------------------------------------
-
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
>

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to