Events in COM
Posted on 2003-03-21
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...
for x := 1 to 10 do
CounterProp := x;
If FEvents <> nil then FEvents.onCounterChange;
MyEventSink := TObject1Events.Create(nil);
MyEventSink.onCounterChange := CounterChange;
MyObject := IObject1.Create;
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);
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.