Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-04

Event with changed signature can be loaded without error

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Werner Pamler

I don't know: is this changed or am I fooled by my memory? I was rather sure that when the signature of a published event is changed, forms saved with the old signature cannot be read without error. But now I notice that this is not true any more.

The version of TAChart which I just committed to trunk had to change the signature of the TChartDataPointDrawEvent event from

    procedure (ASender: TDataPointDrawTool) of object;

to

  procedure (ASender: TDataPointDrawTool;  ADrawer: IChartDrawer) of object;

Testing this with the demo in folder
(lazarus)/components/tachart/demo/tools in which the event is handled I was expecting an error - but no, the program compiles and runs fine as if nothing had changed.

Am I missing something?

Reply by email

Mattias Gaertner
to Werner Pamler
I don't know: is this changed or am I fooled by my memory? I was rather sure that when the signature of a published event is changed, forms saved with the old signature cannot be read without error. But now I notice that this is not true any more.

Loading a form only checks the name, not the signature.

Show quoted text 16 lines
The version of TAChart which I just committed to trunk had to change the signature of the TChartDataPointDrawEvent event from    procedure (ASender: TDataPointDrawTool) of object; to  procedure (ASender: TDataPointDrawTool;  ADrawer: IChartDrawer) of object; Testing this with the demo in folder (lazarus)/components/tachart/demo/tools in which the event is handled I was expecting an error - but no, the program compiles and runs fine as if nothing had changed. Am I missing something?

You were just lucky.

Mattias

Reply by email

Ondrej Pokorny
to Werner Pamler: I don't know: is this changed or am I fooled by my memory? I was rather sure that when…
Werner Pamler wrote
I don't know: is this changed or am I fooled by my memory? I was rather sure that when the signature of a published event is changed, forms saved with the old signature cannot be read without error. But now I notice that this is not true any more.

AFAIR it has always been so. Didn't you mix up with virtual methods?

Show quoted text 9 lines
The version of TAChart which I just committed to trunk had to change the signature of the TChartDataPointDrawEvent event from    procedure (ASender: TDataPointDrawTool) of object; to  procedure (ASender: TDataPointDrawTool;  ADrawer: IChartDrawer) of object;

You must never change the signature of published events. You pick up a new name, deprecate the old one and after a stable release you delete the deprecated one. In this way you still break compatibility, but in a way that the user is notified about it.

I hope you will have more understanding for breaking changes in the future after this experience :)

Ondrej

Reply by email

Werner Pamler
to Ondrej Pokorny
Ondrej Pokorny wrote 7 lines
On 12.04.2019 19:35, Werner Pamler via lazarus wrote: > I don't know: is this changed or am I fooled by my memory? I was > rather sure that when the signature of a published event is changed, > forms saved with the old signature cannot be read without error. But > now I notice that this is not true any more. AFAIR it has always been so. Didn't you mix up with virtual methods?

I mixed up loading and and toggling between form and code view, and my memory refers to Delphi. I just tested it again: After loading a D7 project with a VirtualTreeView into Delphi XE2 and pressing F12 to toggle to Form view I get the error "Method ... to which VirtualStringTree1.OnGetText refers has an incompatible parameter list" because the D7 event signature contains a widestring parameter, but the XE2 event contains a normal string parameter. - When i load the toolsdemo mentioned in the first message into Lazarus and press F12 nothing happens although the parameter list is different. Strange.

Show quoted text 7 lines
You must never change the signature of published events. You pick up a new name, deprecate the old one and after a stable release you delete the deprecated one. In this way you still break compatibility, but in a way that the user is notified about it. I hope you will have more understanding for breaking changes in the future after this experience :)

Don't worry, it will be changed shorty, but I wanted to have an example which every interested reader could test easily without having to install anything.

Reply by email

Ondrej Pokorny
to Werner Pamler: I mixed up loading and and toggling between form and code view, and my memory refers to…
Werner Pamler wrote 7 lines
Am 12.04.2019 um 20:23 schrieb Ondrej Pokorny via lazarus: > I hope you will have more understanding for breaking changes in the > future after this experience :) Don't worry, it will be changed shorty, but I wanted to have an example which every interested reader could test easily without having to install anything.

No problem with that. I know that sometimes it is necessary to change the parameters of e.g. a virtual method even if it means that libraries supporting several Lazarus versions have to use IFDEFs for the overrides. I do understand it.

Ondrej

Reply by email