Solved

OnChange Custom Event in Delph win32

Posted on 2009-07-16
1
266 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

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