?
Solved

Events in COM

Posted on 2003-03-21
4
Medium Priority
?
212 Views
Last Modified: 2010-05-18
I am new to com programming and have a general question.

I have a simple server that increments a counter from 1 to 10.  Each time the counter is incremented, an event is fired.  I simply want to add the value of the counter into a TMemo in the client. I currently have the client going back to the server to get the value of the counter through a published property but this seems a little unnecessary...

*** server
proc startLoop
begin
for x := 1 to 10 do
  CounterProp := x;
  If FEvents <> nil then FEvents.onCounterChange;
end;

*** Client
proc CounterChange;
begin
  Memo1.Lines.Add(IntToStr(Object1.CounterProp));
end;

proc StarttheLoop
begin
  MyEventSink := TObject1Events.Create(nil);
  MyEventSink.onCounterChange := CounterChange;
  MyObject := IObject1.Create;
  MyEventSink.Connect(MyObject);
  MyObject.StartLoop;
  MyEventSink.Free;
end;

I think it would make more sense to have the event send the value of the counter back as a parameter of CounterChange so that the client does not have to make another trip[ to the server. ie..

proc CounterChange(CurrentCounter: Integer);
begin
  Memo1.Lines.Add(IntToStr(CurrentCounter));
end;

I have tried this, but when I try "MyEventSink.onCounterChange := CounterChange" I get the error "Incompatible types: TObject and Integer"

When I try 'MyEventSink.onCounterChange := CounterChange(ANumber);" I get the error "Incompatible types:
'TIObject1EventsonRecordChangeEvent' and 'procedure, untyped pointer or untyped parameter'"

My question is... Is it better to do this with the published property.  If no, then I will increase points and continue.
0
Comment
Question by:ssunko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
hinnack earned 400 total points
ID: 8200840
0
 

Expert Comment

by:CleanupPing
ID: 9316640
ssunko:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 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