📜 ⬆️ ⬇️

Delphi: How to get rid of published properties

Introductory



While working on PostgresDAC , our team encountered this problem twice. And both times the changes affected the component TPSQLDump , as the most intensively changing. This is understandable; every serious release of the PostgreSQL server sometimes makes significant changes to the pg_dump parameters. And our task is full compatibility of TPSQLDump with pg_dump.


')
The fact is that information about published properties is stored in DFM files. And simply removing the property (or changing it), when loading the component, we get an error message. If there are many such components, the process promises to be tedious.

Task



Replace the TPSQLDump.TableName: string property with the TPSQLDump.TableNames: TStrings . In essence, it is necessary to implement the possibility of dumping several specified tables instead of one.

Decision



The code speaks for itself:

TPSQLDump = class (TComponent)
private
...
procedure ReadTableName (Reader : TReader) ;
protected
procedure DefineProperties (Filer : TFiler) ; override ;
...
published
...
//property TableName: string ...
property TableNames : TStrings read FTableNames
write SetTableNames ;
...
end ; //TPSQLDump

implementation

...

procedure TPSQLDump . DefineProperties (Filer : TFiler) ;
begin
inherited ;
Filer . DefineProperty( 'TableName' , ReadTableName , nil , False ) ;
end ;

procedure TPSQLDump . ReadTableName (Reader : TReader) ;
var S : string ;
begin
S := Reader . ReadString ;
if S > '' then FTableNames . Append(S) ;
end ;


Explanations



We define the ( Filer.DefineProperty ) TableName property in the overlapped DefineProperties method. The ReadTableName method will read the values ​​of the TableName . Since we did not assign a method for writing (we passed nil second parameter), this property will never be saved in the future. Problem solved.

By the way, VCL developers often use this trick.

PS
Thanks to Alexey Vukolov aka vuk for the idea.

Source: https://habr.com/ru/post/75932/


All Articles