Jump to content

Add ClientEvents.ExtEvents in runtime when component is created in desing time


MarcoZC

Recommended Posts

In the source I write this command to assing a clientevent.extevent. If run the application it does not work bud if I assign this in dessign time work ok.

z := 'afterrender=function afterrender(sender, eOpts) { sender.allowBlank = false; }';

TUniDBDateTimePicker(edit).ClientEvents.ExtEvents.Add( z );

I need make another job to meke work this code??

Link to comment
Share on other sites

7 minutes ago, MarcoZC said:

In the source I write this command to assing a clientevent.extevent. If run the application it does not work bud if I assign this in dessign time work ok.

Hello,

http://forums.unigui.com/index.php?/topic/11352-clienteventsextevents-not-fire-if-added-in-runtime-mode-if-control-is-also-created-at-runtime/&do=findComment&comment=60231

Link to comment
Share on other sites

35 minutes ago, Sherzod said:

if we create the component at runtime this may work (it seems that the key is to assign a name to the component). But as I said, I create the components at design time, so that they already have a name, and then at runtime I want to assign the afterrender depending on the Datasource field having the required property set to true. This is the code I use, but it doesn't work.

procedure TUniManPol.GetRequiredField;
var
   x: integer;
   o: TComponent;
   f: TField;
   c, z : string;
begin
   z := 'afterrender=function afterrender(sender, eOpts) { sender.allowBlank=false; }';
   for x := 0 to ComponentCount-1 do
   begin

     o := Components[x];

    c := '';

    f := nil;
    t := '';   // Tipo de dbedit
    if o is TUniDBEdit then
    begin
      t := 'TUniDBEdit';
      c := TUniDBEdit(o).DataField;
      f := TUniDBEdit(o).Datasource.Dataset.fieldbyName(c);
      if f.Required then
      begin
           TUniDBEdit(o).ClientEvents.ExtEvents.Add( z );
           TUniDBEdit(o).ClientEvents.Enabled := True;
      end;
    end;
    if o is TUniDBDateTimePicker then
    begin
      t := 'TUniDBDateTimePicker';
      c := TUniDBDateTimePicker(o).DataField;
      f := TUniDBDateTimePicker(o).Datasource.dataset.fieldbyName(c);
      if f.Required then
      begin
         TUniDBDateTimePicker(o).ClientEvents.ExtEvents.Add( z );
         TUniDBDateTimePicker(o).ClientEvents.Enabled := True;
      end;
    end;
    if o is TUniDBLookupComboBox then
    begin
      t := 'TUniDBLookupComboBox';
      c := TUniDBLookupComboBox(o).DataField;
      f := TUniDBLookupComboBox(o).Datasource.dataset.fieldbyName(c);
      if f.Required then
      begin
         TUniDBLookupComboBox(o).ClientEvents.ExtEvents.Add( z );
         TUniDBLookupComboBox(o).ClientEvents.Enabled := True;
      end;
    end;

  end;

end;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...