--- ---
type TMyClass = class protected FProp1: string; bIsChanged: Boolean; public property Prop1: string read FProp1 write SetProp1; end;
property Prop1: string read FProp1 write FProp1;
There is no way to avoid having a SetProp method, however the number of methods can be reduced by sharing a single SetProp method for all properties of a single type. The secret is to use the Indexed Property feature. The following is extracted from my TVersionInfo component:
{ ... } private procedure SetVerProp(index: integer; value: TControl); function GetVerProp(index: integer): TControl; published property CtlCompanyName: TControl index 1 read GetVerProp write SetVerProp; property CtlFileDescription: TControl index 2 read GetVerProp write SetVerProp; property CtlFileVersion: TControl index 3 read GetVerProp write SetVerProp; property CtlInternalName: TControl index 4 read GetVerProp write SetVerProp; property CtlLegalCopyRight: TControl index 5 read GetVerProp write SetVerProp; property CtlOriginalFileName: TControl index 6 read GetVerProp write SetVerProp; property CtlProductName: TControl index 7 read GetVerProp write SetVerProp; property CtlProductVersion: TControl index 8 read GetVerProp write SetVerProp; end;
In your case you do not need the GetXXX method though it could also be used. The SetXXX method uses a simple case statement to set the right member:
procedure TVersionInfo.SetVerProp(index: integer; value: TControl); begin case index of 1: FCtlCompanyName := Value; 2: FCtlFileDescription := Value; 3: FCtlFileVersion := Value; 4: FCtlInternalName := Value; 5: FCtlLegalCopyRight := Value; 6: FCtlOriginalFileName := Value; 7: FCtlProductName := Value; 8: FCtlProductVersion := Value; end; Refresh; end;
In your case, you can replace Refresh with setting the bIsChanged value.