0

I'm looking for the code that checks if the event is assigned, and if so, fires it.

What code manage the events?

Suggestions?

I have a custom component, that is connected to AdoQuery, that hold TField. My component, does not fire the OnSetText of the TField, while other components allow the fire of the OnSetText even. im trying to locate the reason.

ok, here is source code:

procedure TForm1.ADOQuery1MydateSetText(Sender: TField; const Text: string);
var
  Garbage:TDateTime;
begin
  if TryStrToDate(text,Garbage) then
    Sender.AsString := Text
  else ShowMessage('so now what?');
end;

How to trace the code that makes the call to this code, inside Delphi?

0

1 Answer 1

7

Typically an event handler will be declared with a property declared like this:

property OnMyEvent: TMyEvent read FOnMyEvent write FOnMyEvent;

So, in order to fire it the code will execute FOnMyEvent and so you need to search the component's source code for references to FOnMyEvent or possibly OnMyEvent. Usually you will find something like this:

procedure TMyComponent.DoMyEvent;
begin
  if Assigned(FOnMyEvent) then
    FOnMyEvent(Self);
end;

Finally, you need to look for the places where DoMyEvent is called.


As a worked example, we can use the OnSetText event of TField. This is declared like this:

property OnSetText: TFieldSetTextEvent read FOnSetText write FOnSetText;

That's the only reference to OnSetText. So we look for FOnSetText which leads to this:

procedure TField.SetEditText(const Value: string);
begin
  if Assigned(FOnSetText) then FOnSetText(Self, Value) else SetText(Value);
end;

Now, SetEditText is a private method, so we don't need to look outside the unit in which it is declared. And the only place it is used is as the property setter for TField.Text:

property Text: string read GetEditText write SetEditText;

Then you could continue and look for the places where that property is assigned to, but there will be a lot of places where that happens. So, if you want to debug all this you simply need to enable Debug DCUs and set a breakpoint inside TField.SetEditText. You may wish to make the break point condition on the content of Value if your find that the break point fires too often.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.