Author Topic: Delphi Properties  (Read 1509 times)

greygor

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Delphi Properties
« on: January 15, 2002, 04:47:04 am »
Is their any sign of implementing property generation for delphi properly?

Simple case

TBatch = class
   FBatchName : string;
end;

If FBatchName was to be a property then it would be

 TBatch = class
 private
   function GetBatchName: string;
   procedure SetBatchName(const Value: string);
 public
   property BatchName: string read GetBatchName write SetBatchName;
 end;

Along with the skeleton functions in the implementation section.


This fuctionality would greatly enhance the usability of the product for all Delphi users.

When reverse engineering the code a recognition of this construct would also be useful.

Mark Stansfield
Runtime Technology
Certified Delphi Developer
Ceritfied Delphi Trainer

sparks

  • EA Administrator
  • EA User
  • *****
  • Posts: 591
  • Karma: +3/-0
    • View Profile
Re: Delphi Properties
« Reply #1 on: January 16, 2002, 05:28:44 am »
Hello,

We will need to consider the ways we can implement this request, because it will require a rethink to the way EA works currently.  To this correctly an attribute really needs to be defined (FBatchName is the case below) as a property and EA automatically creates (virtual) operations (GetBatchName and SetBatchName) that can't be modified manually.  Currently there is no link between the attributes and operations.

Do you agree?

Paul Mathers

greygor

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: Delphi Properties
« Reply #2 on: January 16, 2002, 08:45:41 am »
I think I understand what you've written.  The end result is that if I defined an attribute in Enterprise Architect and called it BatchName and gave it a data type of string.  If I then requested that it be defined as a property the code generated would be as follows:

unit TBatch1;

interface

Type
 TBatch1 = class
 private
   FBatchName : string;
   function GetBatchName: String;
   procedure SetBatchName(const Value: String);
 public
   property BatchName: String read GetBatchName write SetBatchName;
 end;

implementation

{ TBatch1 }

function TBatch1.GetBatchName: String;
begin
 Result := FBatchName;
end;

procedure TBatch1.SetBatchName(const Value: String);
begin
 FBatchName := Value;
end;

end.

It would create a private field of the same name but prefix it with 'F' (which reminds users not to address it directly.  It would then create a private function that can read this value called GetBatchName and a private function that sets this value called SetBatchName.  Both of these are Static methods by default.

Is that any clearer?