Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Indy: Using Event w/ Dynamically Created Control

Posted on 2002-05-24
3
Medium Priority
?
295 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 1200 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

879 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