Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom control inherited from IWControls
#1
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!
Reply
#2
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.
Reply
#3
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)