To my big suprise the property 'Name' is overridden in the TWPFGGraphic class and this just breaks up my complete code. Let me explain why...
I have a form on which I drop several of these graphics. I have an additional stringlist where the names for these graphics are stored. These names are entered by the user in runtime because there will also be bands and other controls that will link to just this name. So I have code like this:
var
TableGraphic: TTableGraphic;
ControlName: string;
ValidReply: Boolean;
begin
ValidReply := False;
repeat
ControlName := TableGraphicList.NewTableName;
if InputQuery( 'New data control', 'Please enter a valid name for this new control.', ControlName ) then begin
ControlName := Trim( ControlName );
try
if ( Length( ControlName ) = 0 ) or not IsValidIdent( ControlName ) then raise Exception.Create( 'You must provide a valid control name.' );
if TableGraphicList.HasControlName( ControlName ) then raise Exception.CreateFmt( 'Control "%s" already exists.', [ ControlName ] );
ValidReply := True;
except on E: Exception do DisplayException( E );
end;
end
else begin
ControlName := '';
ValidReply := True;
end;
until ValidReply;
if ( Length( ControlName ) > 0 ) then TableGraphic := TTableGraphic( FD.NewObjectEx( wpfCustomObject, WPFRect( 0, 0, 3, 1 ), ControlName, TTableGraphic.ClassName ) );
end;
Alles anzeigen
The TableGraphicList object is my list of graphics. DisplayException will log and display the exception without reraising the exception. Basically, I let the user enter a name for the control until he has entered a valid name. (IsValidIdent is a Delphi function, btw.)
The magic in my class is that in the SetName method that I've overridden, I add the name to a list and do some further processing with this name. (E.g. adding to a dropdown box, writing the name to a log, things like that.)
However, since the inherited 'Name' property is hidden by the new 'Name' property, this just doesn't work. I could of course work around this by adding my own, new 'Name' property and assign some methods to it to use the inherited name property but personally, I feel this a bit bad design.
Was there any need to override the Name property in WPForms? It's a really annoying thing that took me half a day to discover, and I only discovered it because I have checked the source.