Atozed Forums
Custom control inherited from IWControls - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Custom control inherited from IWControls (/thread-1118.html)



Custom control inherited from IWControls - LeoBruno - 06-29-2019

Hi:

I´m developing some IWControls inherited from TIWEdit.

I would like to ask for help, since I´m having a few problems with the inherited controls in design time.

I must say that I´m using IW 14 bundled version (delphi 10.3), so no access to the source code avaiable.

1# - Inherited controls doesn´t look like their parents in design time. (see picture attached). (solved, see the post bellow)
2# - Not possible to assign ScriptAvents through a method called by other property setter.

There is a boolean property, and based on it´s value a method gets some javascripts in order to be set at scriptevents.
The boolean property setter, after defining the property value, calls the method to add the script events.
The method is being called properly, but before adding the new scripts, is necessery to delete the old ones.
If the old scriptevents are not deleted, the new one is not added.

So, the SetJavaScripts method, looks like this:


procedure TLBIWXEditFloat.SetJavaScripts(aAllowNegative: boolean);
var
  _Idx: Integer;
  _OnKeyDown: TStringList;
begin
  _Idx := Self.ScriptEvents.IndexOf('onKeyDown');

  if _Idx > 0 then
    Self.ScriptEvents.Delete(_Idx);

_OnKeyDown := TLBXIntraWebJs.GetScrptEdtFloatOnKeyDown(aAllowNegative);
  try
    Self.ScriptEvents.Add('onKeyDown', _OnKeyDown.Text);
  finally
    _OnKeyDown.Free;
  end;
end;

The problem is that in design time, "Self.ScriptEvents.IndexOf('onKeyDown')" always returns -1, therefore is impossible to delete the scriptevent, preventing to add the new one.

AllowNegative setter looks like this:

procedure TLBIWXEditFloat.SetAllowNegative(const Value: Boolean);

begin

  FAllowNegative := Value;

  Self.SetJavaScripts(Value);
end;

What am I missing?

Thanx in advance!


RE: Custom control inherited from IWControls - LeoBruno - 07-01-2019

After talking to chad at support chat, I´ve managed to solve the first problem. (1# - Inherited controls doesn´t look like their parents in design time. (see picture attached).)

I had to mark the package with the descendent controls as Only Runtime, created another package Only Designtime, and to register the painters for the controls.

Like this:

initialization
  IWRegisterPaintHandler('TLBIWXEdit', TIWPaintHandlerEdit);

Also, moved the register procedure to the design time package.


RE: Custom control inherited from IWControls - Alexandre Machado - 07-01-2019

As I responded in the portuguese channel, don't use the TOwnedCollection (TIWScriptEvents ancestor) methods.

TIWScriptEvents have specific methods to handle adding/updating code:

TIWScriptEvents.HookEvent(const AEventName: string; AEventCode: string);

HookEvent will add a new event or update existing event using the provided code.