Reputation: 7438
I want to trigger all onChange events of all TMemo components in a form, when the form is shown.
For this i'm using the code below :
var
i: integer;
m: tmemo;
begin
for i := 0 to componentcount - 1 do
begin
if components[i] is tmemo then
begin
m := components[i] as tmemo;
m.onchange(m);
end;
end;
end;
Problem is, i'm getting some Access Violations on the loop above, probably due the fact some memos don't have an onChange event.
How can i test if the event exists, before trigger it on the line below ?
m.onchange(m);
Upvotes: 0
Views: 532
Reputation: 597205
You need to check if an event handler is assigned before calling it :
if Assigned(m.OnChange) then
m.OnChange(m);
Upvotes: 3