Solved

Indy: Using Event w/ Dynamically Created Control

Posted on 2002-05-24
3
289 Views
Last Modified: 2012-05-04
In my application I'm dynamically creating the TIdHTTP component and I would like to use the OnWork and OnWorkBegin events.  How do I do this when the component is created dynamically?  I've tried adding:

procedure httpWorkBegin(Sender: TObject; AWorkMode: TWorkMode; const
AWorkCountMax: Integer);
begin
  //
end;

to the procedure that creates and uses the http component but when I try to assign it to the http component using:  http.OnWorkBegin := httpWorkBegin; it gives me the error "Incompatible types: method pointer and regular procedure".

Anyone know what's wrong or how I should be doing this?
0
Comment
Question by:dokken
3 Comments
 
LVL 4

Accepted Solution

by:
nestorua earned 300 total points
ID: 7033265
HI,
You must declare your "procedure httpWorkBegin" as a method of
for example your Form "procedure TMyForm.httpWorkBegin", not as a simple procedure, because an event is a pointer to some procedure OF OBJECT not simple procedure type.
TWorkBeginEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer) OF OBJECT;

Sincerely,
Nestorua.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7034389
so it should look like this :

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure httpWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
      const AWorkCountMax: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.httpWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
  const AWorkCountMax: Integer);
begin

end;

end.
0
 

Author Comment

by:dokken
ID: 7036461
That worked.  For some reason I thought I needed to add the event code in the procedure that was creating the HTTP component.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question