Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Procedures ...

rs@chello.nors@chello.no Member Posts: 17
Hi.

How to create procedures for objects created at runtime?

I have an ActiveX that I have created at runtime. I know this object has an "OnDisconnect" -event, and I need to use it.
I have tried some things, but without any luck....

I have followed the default pattern in my unit, and I get noe errors, but it will not work.

Is there a secret, or have I just had "bad luck", and should try again?

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi.
    :
    : How to create procedures for objects created at runtime?
    :
    : I have an ActiveX that I have created at runtime. I know this object has an "OnDisconnect" -event, and I need to use it.
    : I have tried some things, but without any luck....
    :
    : I have followed the default pattern in my unit, and I get noe errors, but it will not work.
    :
    : Is there a secret, or have I just had "bad luck", and should try again?
    :
    First of all, all events are NOT procedures, but methods. This means that you need to write an event-method with the correct parameter list. This procedure needs to be in the public section of the form (or another object). Here is a small example, which creates buttons at runtime and links an event to their OnClick() event:
    [code]
    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls;

    type
    TForm1 = class(TForm)
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    i: integer;
    public
    procedure RuntimeButtonClick(Sender: TObject);
    // event declaration
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.RuntimeButtonClick(Sender: TObject);
    begin
    ShowMessage('Button Clicked');
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    var
    B: TButton;
    begin
    B := TButton.Create(Self);
    with B do begin // set the button properties
    Left := 10;
    Top := i;
    Width := 100;
    Height := 21;
    Caption := 'Runtime';
    inc(i, 30); // increase top for new button
    OnClick := RuntimeButtonClick; // link event to button
    Parent := Self;
    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    i := 10; // initial top
    end;

    end.
    [/code]
  • rs@chello.nors@chello.no Member Posts: 17

    My God . . . Your a genius !

    Thanks 10.000 times :-)

    Regards,
    Roald
Sign In or Register to comment.