Solved

OnChange Custom Event in Delph win32

Posted on 2009-07-16
1
259 Views
Last Modified: 2012-05-07
type
  TStatus   =  (NEW, ACTIVE, NOT_ACTIVE);

  type TDoFirstEvent = procedure (Sender: TObject) of object;

private
FOnChange : TDoFirstEvent;
FTypeStatus : TStatus;
//
published
property OnChange :  TDoFirstEvent read FOnChange write FOnChange;

// Dispatch method
procedure TBase.DoChange;
begin
if (Assigned (FOnChange) and (FTypeStatus = NEW))  then
begin
   sleep(500);
   FOnChange(Self);
end;
end

A Form contains an object of type TBase and in myform.create I do:

OnChange := DoFirst;

// DoFirst is an procedure of TDoFirstEvent type

My goal is to call DoFirst everytime OnChange is set and
FTypeStatus is NEW. It doesn't work, what is wrong in my approach?
:-(
0
Comment
Question by:jaja2005
[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
1 Comment
 
LVL 11

Accepted Solution

by:
dougaug earned 500 total points
ID: 24869270
Hi,

in the code above, you aren't calling DoFirst and not triggering the OnChange event in any moment. he fact of assigning DoFirst method to OnChange property doesn't call the DoChange method.

If you want to call DoFirst, you should first assign it to OnChange property (as you've done) and in other part of your code you should call DoChange method.

Example:

procedure TBase.SetPropertyString(Value: String);
begin
  if PropertyString <> 'Value' then
  begin
     PropertyString := Value;
     DoChange;
  end
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 166
CheckListBox usage 3 82
how to change, disabled button color FMX ? 1 51
Delphi problems to abort a printjob 9 34
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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