delphi - Is this the right way to expose sub-methods that I want to group logically in a class? -


I have a base object, TCustomerDocument, TCustomerDocument has two address addresses, home and business, which I logically Would like to group as TCustomerDocument.HomeAddr and TCustomerDocument.BusinessAddr So I can write code like MyCustomerDocument.HomeAddr.Line1 to read the first address line of the home address from the document.

The catch is that those addresses are within the second class (TDocumentHeader) within the TC client document:

  TCustomerDocument TDocumentHeader (address field) Is here)  

Now I

  MyCustomerDocument.DocumentHeader.GetField ('HOMEADDR1') AsString  

To reach the home address line first.

TDocumentHeader will have two addresses (home and business) started with creating only one TAddressInfo object:

  TCustomerDocument Home: TAddressInfo Business: TAddressInfo TDocumentHeader (Address Fields are here)  

And it works just fine. The related parts of the code are as follows:

  type TCustomerDocument = class; // fwd announcement TAddressInfo = class (TObject) private fDocumentHeader: TCustomerDocument; Destruction of Destruction; Override; Create a public constructor (a custom document: TCustomerDocument); Function Addr1: string; End; TCustomerDocument = Class (Tubect) Public Home AdWords: TADDERFO; BusinessAddr: TAddressInfo  

Then I have it in TCustomerDocument.Create:

  HomeAddr: = TAddressInfo.Create (Self); BusinessAddr: = TAddressInfo.Create (self);  

[I have left the clean / free code for brevity.]

I need no access to TAddressInfo objects (at this point) Not - I just want to use it to group the areas to clear the code code.

Q: Is this code the right way to collect those areas in group or is there an easy way (possibly a structure in a record class)?

The solution for what you want to do is to use properties in TCustomerDocument

  TAddress = class (TObject) Private line list: TStringlist;  

Something like this (from top of my head):

Protected function GetLines (index: integer): string; Process setline (index: integer; command value: string); Public Property Lines [Index: Integer]: String is read GetLines writes SetLiines; ... End; TCustomerDocumentHeader = Class (TObject) Public Home: Address: Tedder; Business Address: Tedder; ... End; TCustomerDocument = Classes (TOBAGES) Private FD Document Header: TCustomerDocumentHeader; Function GetBusinessAddress: TAddress; Process SetBusinessAddress (const Price: TAddress); GetHomeAddress Function: TAddress; Process SetHomeAddress (const Price: TAddress); ... Public Property Document Header: Write TC Client Document Header FDIdate header FDC Header; Property Business Academy: Tedder Write GetBusinessAddress SetBusinessAddress; Property HomeAssembly: Tedder read the Gatehome Address SetHomeAddress; ... End; Implementation function TAddress.GetLines (index: integer): string; Start the result: = line list [index]; End; Process tedder.setline (index: integer; command value: string); Lineline start [index]: = value; End; Function TCustomerDocument.GetBusinessAddress: TAddress; Start the result: = DocumentHeader.BusinessAddress; End; Function TCustomerDocument.GetHomeAddress: TAddress; Start the result: = DocumentHeader.HomeAddress; End; Process TCustomerDocument.SetBusinessAddress (const Price: TAddress); Start DocumentHeader.BusinessAddress: = Value; End; Process TCustomerDocument.SetHomeAddress (const Price: TAddress); Start DocumentHeader.HomeAddress: Value =; End;

Then you can do things like

  MyDocument.BusinessAddress.Lines [n]: = '1 test lane';  

etc.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -