?
Solved

Events in COM

Posted on 2003-03-21
4
Medium Priority
?
217 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
2 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

580 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