Is it only me or this code from the Delphi RTL source is really strange:

Is it only me or this code from the Delphi RTL source is really strange:

procedure TDelegatedOleControl.CreateControl;
var
Stream: IStream;
CS: IOleClientSite;
X: Integer;
begin
FOleControl := nil;
if FOleControl = nil then
try
.....

FOleControl is made nil and then checked. This sounds like trouble. Any opinions?

Comments

  1. Bogdan D​ from what I recollect talking to long gone R&D members in the days this code was created, it's probably a workaround the many buggy OLE control implementations.

    Similarly, many VCL wrappers around Windows controls need to recreate these controls when certain properties are changed. There the VCL controls (often over time learned to) know under what circumstances they need to.

    Given the vast realm of OLE controls the central code needs to do this.

    ReplyDelete
  2. Jeroen Wiert Pluimers Looks like a bug to me. CreateControl is the first line called in GetOleObject, GetProperty, SetProperty, DoObjectVerb (methods of TDelegatedOleControl), so that code can get called very often. For instance each time you set the "Visible" property of a control, a new control is created, but the existing one is never destroyed.

    ReplyDelete
  3. Bogdan D OLE is slow anyway, the existing control will go away when the reference count reaches 0, this likely fixes much severe issues, VCL does this too but on a more fine grained scale.

    ReplyDelete

Post a Comment