Ok, you're nearly there with the Delphi Import/Export, but there are some major problems.
Let's deal with Interfaces first.
INTERFACE SOURCE
ICommunicate = interface
procedure Speak(Message: string);
function Agree(Message: string): Boolean;
end;
When imported the procedure and function is protected scope rather than public scope. There is no scoping for interfaces.
When we forward engineer this from EA then the following is generated
GENERATED INTERFACE SOURCE
unit InterfaceTestGen;
interface
uses
system, graphics;;
type
ICommunicate = interface (TObject)
protected
procedure Speak(Message: string);
function Agree(Message: string): Boolean;
end;
implementation
procedure ICommunicate.Speak(Message: string);
begin
end;
function ICommunicate.Agree(Message: string): Boolean;
begin
end;
end.
1. There should only be one semi-colon after the Uses Clause.
2. The ultimate ancestor of Interface is IInterface, not TObject.
3. Interfaces are implemented in classes and so have no implementation.
4. There is no scoping allowed as Public is the default.
what should be generated is
unit InterfaceTestGen;
interface
uses System;
Type
ICommunicate = interface
procedure Speak(Message: string);
function Agree(Message: string): Boolean;
end;
implementation
end.
Now for Classes
CLASS SOURCE
unit ClassTest;
interface
uses system, graphics;
Type
TMammal = class(TObject, ICommunicate)
private
FEyeColour: TColor;
procedure SetEyeColour(const Value: TColor);
protected
function Agree(Message: string): Boolean;
published
property EyeColour: TColor read FEyeColour write SetEyeColour;
procedure Testing;
public
procedure Speak(Message: string);
end;
THuman = class(TMammal)
automated
procedure Test2(MyOtherTest: TFont);
end;
TAlmostHuman = class(TMammal)
procedure Test3(MyLastTest: Boolean);
end;
implementation
function Test1(MyTest: integer): string;
begin
//code
end;
{ TMammal }
function TMammal.Agree(Message: string): Boolean;
begin
//code
end;
procedure TMammal.SetEyeColour(const Value: TColor);
begin
FEyeColour := Value;
end;
procedure TMammal.Speak(Message: string);
begin
//code
end;
procedure TMammal.Testing;
begin
//code
end;
{ THuman }
procedure THuman.Test2(MyOtherTest: TFont);
begin
//code
end;
{ TAlmostHuman }
procedure TAlmostHuman.Test3(MyLastTest: Boolean);
begin
//code
end;
end.
As we can See TMammal is descended from TObject and Implements the Interface ICommunicate. It uses the 4 main scoping directives of Delphi; Private, Protected, Published and Public.
when we reverse engineer the TMammal class we get the following.
unit classTestGen;
interface
type
TMammal = class (TObject)
public
procedure Speak(Message: string);
protected
function Agree(Message: string): Boolean;
private
FEyeColour: TColor;
procedure SetEyeColour(Value: TColor);
end;
implementation
procedure TMammal.Speak(Message: string);
begin
end;
function TMammal.Agree(Message: string): Boolean;
begin
end;
procedure TMammal.SetEyeColour(Value: TColor);
begin
end;
end.
As you can see neither the published method Testing nor the published property has been generated. Thinking that this was a problem with recognising Published scoping I put a property in the public section and resynchronised and then forward engineered the class. This resulted in the following.
type
TMammal = class (TObject)
public
procedure Speak(Message: string);
protected
function Agree(Message: string): Boolean;
private
FEyeColour: TColor;
FEyeColour2: TColor;
procedure SetEyeColour(Value: TColor);
procedure SetEyeColour2(Value: TColor);
public
property +EyeColour2:TColor read FEyeColour2 write SetEyeColour2;
end;
As you can see we now have the property generated but in a separate public section from the other public procedure and we have a '+' concatenated on the fromt of the property name. So apart from that it is right.
Next, Delphi default scoping.
If in a Delphi unit 'Forms' is in the Interface uses clause then the default scoping is Published, else it is Public. Thus
TAlmostHuman = class(TMammal)
procedure Test3(MyLastTest: Boolean);
protected
procedure Test4;
end;
If 'Forms' in the uses clause then Test3 is Published, otherwise it is Public.
Finally, Automated. This is legacy so you may not want to bother but
THuman = class(TMammal)
automated
procedure Test2(MyOtherTest: TFont);
end;
is a perfectly valid piece of Delphi code. Not sure how you would identify this in UML or EA.
I hope this has been some help, if you have any questions please don't hesitate to contact me.
Mark Stansfield
Senior Developer/Trainer
Runtime Technology
www.runtime.co.ukmark@runtime.co.uk