Advertisement

04.15.2008 at 02:11AM PDT, ID: 23323005
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Delphi 7 :: New descendant TTimer component :: Overwrite OnTimer event

Hi All,

I would like to create a new TTimer component but overwrite the OnTimer() event.
The overwritten event should return some parameters.
Can someone please help me with this?

Thanks!
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Marius0188
Solution Provided By: ziolko
Participating Experts: 1
Solution Grade: A
Views: 14
Translate:
Loading Advertisement...
04.15.2008 at 02:16AM PDT, ID: 21357083

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 02:29AM PDT, ID: 21357147

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 02:32AM PDT, ID: 21357160

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 02:47AM PDT, ID: 21357212

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:01AM PDT, ID: 21357270

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:13AM PDT, ID: 21357312

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:13AM PDT, ID: 21357313

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:25AM PDT, ID: 21357356

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:26AM PDT, ID: 21357359

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:32AM PDT, ID: 21357382

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:33AM PDT, ID: 21357390

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 03:40AM PDT, ID: 21357418

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 04:13AM PDT, ID: 21357561

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 04:31AM PDT, ID: 21357637

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 04:33AM PDT, ID: 21357654

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 04:39AM PDT, ID: 21357677

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 04:48AM PDT, ID: 21357716

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.15.2008 at 04:50AM PDT, ID: 21357725

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.16.2008 at 12:35AM PDT, ID: 21365513

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.16.2008 at 12:59AM PDT, ID: 21365622

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.16.2008 at 04:20AM PDT, ID: 21366470

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.16.2008 at 04:23AM PDT, ID: 21366480

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.16.2008 at 11:41AM PDT, ID: 21370722

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
04.15.2008 at 02:16AM PDT, ID: 21357083

Rank: Sage

what parameters you want to add?

ziolko.
 
04.15.2008 at 02:29AM PDT, ID: 21357147
I know there might be a similar freeware component available out there but I want to build this myself as an exercise.

The timer should monitor a folder for files and OnTime() event it should then give the list of filenames in a TStrings to user for example:

type
  TOnFilesFoundEvent = Procedure(Sender :TObject; var AFiles :TStrings) of Object;

and the FOnTime event:

    FOnTimer: TOnFilesFoundEvent;


Hope this helps.
 
04.15.2008 at 02:32AM PDT, ID: 21357160

Rank: Sage

little sample:

  TForm1 = class(TForm)
    Button6: TButton;
  private
    procedure OnMyTimer(Sender: TObject;AParam1: Integer;AParam2: string);
  end;


  TExTimerEvent = procedure(Sender: TObject;AParam1: Integer;AParam2: string) of object;

  TMyTimer = class(TTimer)
  private
    FOnExTimer: TExTimerEvent;
    procedure SetOnTimerEx(Value: TExTimerEvent);
    procedure Dummy(Sender: TObject);
    property OnTimer;
  protected
    procedure Timer; override;
  public
    property OnTimerEx: TExTimerEvent read FOnExTimer write SetOnTimerEx;
  end;

procedure TForm1.OnMyTimer(Sender: TObject; AParam1: Integer; AParam2: string);
begin
  ShowMessage(Format('Timer message: %s, timer value: %d', [AParam2, AParam1]));
end;

{ TMyTimer }

procedure TMyTimer.Dummy(Sender: TObject);
begin
//
end;

procedure TMyTimer.SetOnTimerEx(Value: TExTimerEvent);
begin
  FOnExTimer := Value;
  OnTimer := Dummy;
end;

procedure TMyTimer.Timer;
begin
  if Assigned(FOnExTimer) then
    FOnExTimer(Self, Random(MaxInt), 'Hello world');  
end;

ziolko.
 
04.15.2008 at 02:47AM PDT, ID: 21357212

Rank: Sage

...missed a bit of code:

procedure TForm1.Button6Click(Sender: TObject);
var t: TMyTimer;
begin
  t := TMyTimer.Create(Self);
  t.Interval := 1000;
  t.Enabled := True;
  t.OnTimerEx := OnMyTimer;  
end;


ziolko.
 
04.15.2008 at 03:01AM PDT, ID: 21357270
Should I name the new OnTimer() event OnExTimer()?
Can't just override it be naming the new event the same for example: OnTimer()?
Or at least how can I unpublish the old OnTimer() event and only publish the OnExTimer() event?


Thanks
 
04.15.2008 at 03:13AM PDT, ID: 21357312

Rank: Sage

>>Should I name the new OnTimer() event OnExTimer()?
I already gave it new name: OnTimerEx

>>Or at least how can I unpublish the old OnTimer() event and only publish the OnExTimer() event?
TMyTimer = class(TTimer)
  private
    FOnExTimer: TExTimerEvent;
    procedure SetOnTimerEx(Value: TExTimerEvent);
    procedure Dummy(Sender: TObject);
    property OnTimer; <- here standard OnTimer is hidden
  protected
    procedure Timer; override;
  published <- here new property is published
    property OnTimerEx: TExTimerEvent read FOnExTimer write SetOnTimerEx;
  end;

>>Can't just override it be naming the new event the same for example: OnTimer()?
no, because property OnTimer alread exists in base class


of course if you want keep property name OnTimer but have more parameters it's possible by creating new timer component not inherited from TTImer

ziolko.
 
04.15.2008 at 03:13AM PDT, ID: 21357313
Please have a look at my components code.
I have named the event OnTimer() event.
Don't know if this will be a problem.

But the event never gets triggered.
Why?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
unit FolderMonitorTimer;
 
interface
 
uses
  SysUtils, Classes, ExtCtrls, Dialogs, Windows, Consts, Messages, Forms;
 
type
  TOnFilesFoundEvent = Procedure(Sender :TObject; var AFiles :TStrings) of Object;
 
type
  TFolderMonitorTimer = class(TTimer)
  private
    FWatchFolder :String;
 
    FOnTimer: TOnFilesFoundEvent;
 
    procedure SetOnTimer(Value: TOnFilesFoundEvent);
    { Private declarations }
  protected
    Procedure Timer; override;
    { Protected declarations }
  public
    { Public declarations }
  published
    Property WatchFolder :String Read FWatchFolder Write FWatchFolder;
    Property OnTimer :TOnFilesFoundEvent Read FOnTimer Write SetOnTimer;
    { Published declarations }
  end;
 
procedure Register;
 
implementation
 
procedure Register;
begin
  RegisterComponents('Samples', [TFolderMonitorTimer]);
end;
 
{ TFolderMonitorTimer }
 
procedure TFolderMonitorTimer.SetOnTimer(Value: TOnFilesFoundEvent);
begin
  FOnTimer := Value;
end;
 
procedure TFolderMonitorTimer.Timer;
var
  slTemp :TStrings;
  Rec :TSearchRec;
  I :Integer;
begin
  If not Assigned(FOnTimer) then Exit;
  If not DirectoryExists(WatchFolder) then Exit;
  
  slTemp := TStringList.Create;
  Try
    I := FindFirst(WatchFolder + '\*.*', faAnyFile, Rec);
    While I = 0 do
    begin
      If Rec.Name[1] <> '.' then slTemp.Add(WatchFolder + '\' + Rec.Name);
      I := FindNext(Rec);
    end;
  Finally
    slTemp.Free;
  end;
  FOnTimer(Self, slTemp);
end;
Open in New Window
 
04.15.2008 at 03:25AM PDT, ID: 21357356

Rank: Sage

>>But the event never gets triggered.
because TTimer  is active only if original Ontimer property is set.

below complete code for new timer component:

uses Consts;

  TExTimerEvent = procedure(Sender: TObject;AParam1: Integer;AParam2: string) of object;
  TTimerEx = class(TComponent)
  private
    FInterval: Cardinal;
    FWindowHandle: HWND;
    FOnTimer: TExTimerEvent;
    FEnabled: Boolean;
    procedure UpdateTimer;
    procedure SetEnabled(Value: Boolean);
    procedure SetInterval(Value: Cardinal);
    procedure SetOnTimer(Value: TExTimerEvent);
    procedure WndProc(var Msg: TMessage);
  protected
    procedure Timer; dynamic;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Enabled: Boolean read FEnabled write SetEnabled default True;
    property Interval: Cardinal read FInterval write SetInterval default 1000;
    property OnTimer: TExTimerEvent read FOnTimer write SetOnTimer;
  end;

{ TMyTimerEx }

constructor TTimerEx.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FEnabled := True;
  FInterval := 1000;
  FWindowHandle := Classes.AllocateHWnd(WndProc);
end;

destructor TTimerEx.Destroy;
begin
  FEnabled := False;
  UpdateTimer;
  Classes.DeallocateHWnd(FWindowHandle);
  inherited Destroy;
end;

procedure TTimerEx.SetEnabled(Value: Boolean);
begin
  if Value <> FEnabled then
  begin
    FEnabled := Value;
    UpdateTimer;
  end;
end;

procedure TTimerEx.SetInterval(Value: Cardinal);
begin
  if Value <> FInterval then
  begin
    FInterval := Value;
    UpdateTimer;
  end;
end;

procedure TTimerEx.SetOnTimer(Value: TExTimerEvent);
begin
  FOnTimer := Value;
  UpdateTimer;
end;

procedure TTimerEx.Timer;
begin
  if Assigned(FOnTimer) then FOnTimer(Self, Random(MaxInt), 'Hello world');
end;

procedure TTimerEx.UpdateTimer;
begin
  KillTimer(FWindowHandle, 1);
  if (FInterval <> 0) and FEnabled and Assigned(FOnTimer) then
    if SetTimer(FWindowHandle, 1, FInterval, nil) = 0 then
      raise EOutOfResources.Create(SNoTimers);
end;

procedure TTimerEx.WndProc(var Msg: TMessage);
begin
  with Msg do
    if Msg = WM_TIMER then
      try
        Timer;
      except
        Application.HandleException(Self);
      end
    else
      Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;


and I use it like this:

procedure TForm1.OnMyTimer(Sender: TObject; AParam1: Integer; AParam2: string);
begin
  ShowMessage(Format('Timer message: %s, timer value: %d', [AParam2, AParam1]));
end;

procedure TForm1.Button6Click(Sender: TObject);
var t: TTimerEx;
begin
  t := TTimerEx.Create(Self);
  t.Interval := 1000;
  t.Enabled := True;
  t.OnTimer := OnMyTimer;  
end;

ziolko.
Accepted Solution
 
04.15.2008 at 03:26AM PDT, ID: 21357359
Ok please ignore my previous post.

I have changed my code.
OnExTimer() is being use as the event name.

1. The base event OnTimer() still gets published when dropping the component on a form.
    I would like to hide this event in design time.

2. My component still does nothing. The Timer() procedure never executes and therefore the OnExTimer() event never gets trickered. Please have a look at my code and advise:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
unit FolderMonitorTimer;
 
interface
 
uses
  SysUtils, Classes, ExtCtrls, Dialogs, Windows, Consts, Messages, Forms;
 
type
  TOnFilesFoundEvent = Procedure(Sender :TObject; var AFiles :TStrings) of Object;
 
type
  TFolderMonitorTimer = class(TTimer)
  private
    FWatchFolder :String;
 
    FOnExTimer: TOnFilesFoundEvent;
    FOnTimer :TNotifyEvent;
 
    Procedure SetOnExTimer(Value: TOnFilesFoundEvent);
    Procedure Dummy(Sender :TObject);
    { Private declarations }
  protected
    Procedure Timer; override;
    { Protected declarations }
  public
    { Public declarations }
  published
    Property WatchFolder :String Read FWatchFolder Write FWatchFolder;
    Property OnExTimer :TOnFilesFoundEvent Read FOnExTimer Write SetOnExTimer;
    { Published declarations }
  end;
 
procedure Register;
 
implementation
 
procedure Register;
begin
  RegisterComponents('Samples', [TFolderMonitorTimer]);
end;
 
{ TFolderMonitorTimer }
 
procedure TFolderMonitorTimer.Dummy(Sender: TObject);
begin
//Dummy code to disable OnTimer() event in base component.
end;
 
procedure TFolderMonitorTimer.SetOnExTimer(Value: TOnFilesFoundEvent);
begin
  FOnExTimer := Value;
  FOnTimer := Dummy;
end;
 
procedure TFolderMonitorTimer.Timer;
var
  slTemp :TStrings;
  Rec :TSearchRec;
  I :Integer;
begin
  If not Assigned(FOnExTimer) then Exit;
  If not DirectoryExists(WatchFolder) then Exit;
  
  slTemp := TStringList.Create;
  Try
    I := FindFirst(WatchFolder + '\*.*', faAnyFile, Rec);
    While I = 0 do
    begin
      If Rec.Name[1] <> '.' then slTemp.Add(WatchFolder + '\' + Rec.Name);
      I := FindNext(Rec);
    end;
  Finally
    slTemp.Free;
  end;
  FOnExTimer(Self, slTemp);
end;
 
end.
Open in New Window
 
04.15.2008 at 03:32AM PDT, ID: 21357382

Rank: Sage

>>My component still does nothing. The Timer() procedure never executes and therefore the OnExTimer() event never gets trickered.
because you have re-declared FOnTimer which is in base class, event is triggered only when ORIGINAL FOnTimer is set

so remove FOnTimer: TNotifyEvent from your class and change:

procedure TFolderMonitorTimer.SetOnExTimer(Value: TOnFilesFoundEvent);
begin
  FOnExTimer := Value;
  FOnTimer := Dummy;
end;

to

procedure TFolderMonitorTimer.SetOnExTimer(Value: TOnFilesFoundEvent);
begin
  FOnExTimer := Value;
  OnTimer := Dummy;
end;

or use new component from my comment above
ziolko.
 
04.15.2008 at 03:33AM PDT, ID: 21357390

Rank: Sage

>>The base event OnTimer() still gets published when dropping the component on a form.
    I would like to hide this event in design time.

  TFolderMonitorTimer = class(TTimer)
  private
    property OnTimer;

you must hide original property (just like in my first sample)

ziolko.
 
04.15.2008 at 03:40AM PDT, ID: 21357418
OK thanks I got it to work.
No still one problem.

How can I "un-publish" the OnTimer() event which is published in the base class?
It still shows in design time on the events tab of the component.

Thanks.
 
04.15.2008 at 04:13AM PDT, ID: 21357561

Rank: Sage

did you put try this?:

  TFolderMonitorTimer = class(TTimer)
  private
    property OnTimer;

ziolko
 
04.15.2008 at 04:31AM PDT, ID: 21357637
Yes but it still publishes the event.
Any other ideas?
 
04.15.2008 at 04:33AM PDT, ID: 21357654

Rank: Sage

other idea is to create timer based on TComponent like here:
http:Q__23323005.html#21357356

ziolko.
 
04.15.2008 at 04:39AM PDT, ID: 21357677

Rank: Sage

you just have to add your WatchFolder property and do all that stuff with folders in .Timer() method

ziolko.
 
04.15.2008 at 04:48AM PDT, ID: 21357716

Rank: Sage

full code:

  TTimerEx = class(TComponent)
  private
    FInterval: Cardinal;
    FWindowHandle: HWND;
    FOnTimer: TExTimerEvent;
    FEnabled: Boolean;
    FWatchFolder: string;
    procedure UpdateTimer;
    procedure SetEnabled(Value: Boolean);
    procedure SetInterval(Value: Cardinal);
    procedure SetOnTimer(Value: TExTimerEvent);
    procedure WndProc(var Msg: TMessage);
  protected
    procedure Timer; dynamic;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Enabled: Boolean read FEnabled write SetEnabled default True;
    property Interval: Cardinal read FInterval write SetInterval default 1000;
    property OnTimer: TExTimerEvent read FOnTimer write SetOnTimer;
    property WatchFolder: string read FWatchFolder write FWatchFolder;
  end;


{ TMyTimerEx }

constructor TTimerEx.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FEnabled := True;
  FInterval := 1000;
  FWindowHandle := Classes.AllocateHWnd(WndProc);
end;

destructor TTimerEx.Destroy;
begin
  FEnabled := False;
  UpdateTimer;
  Classes.DeallocateHWnd(FWindowHandle);
  inherited Destroy;
end;

procedure TTimerEx.SetEnabled(Value: Boolean);
begin
  if Value <> FEnabled then
  begin
    FEnabled := Value;
    UpdateTimer;
  end;
end;

procedure TTimerEx.SetInterval(Value: Cardinal);
begin
  if Value <> FInterval then
  begin
    FInterval := Value;
    UpdateTimer;
  end;
end;

procedure TTimerEx.SetOnTimer(Value: TExTimerEvent);
begin
  FOnTimer := Value;
  UpdateTimer;
end;

procedure TTimerEx.Timer;
var
  slTemp :TStrings;
  Rec :TSearchRec;
  I :Integer;
begin
  If not Assigned(FOnTimer) then Exit;
  If not DirectoryExists(WatchFolder) then Exit;

  slTemp := TStringList.Create;
  Try
    I := FindFirst(WatchFolder + '\*.*', faAnyFile, Rec);
    While I = 0 do
    begin
      If Rec.Name[1] <> '.' then slTemp.Add(WatchFolder + '\' + Rec.Name);
      I := FindNext(Rec);
    end;
  Finally
    slTemp.Free;
  end;
  FOnTimer(Self, slTemp);

end;

procedure TTimerEx.UpdateTimer;
begin
  KillTimer(FWindowHandle, 1);
  if (FInterval <> 0) and FEnabled and Assigned(FOnTimer) then
    if SetTimer(FWindowHandle, 1, FInterval, nil) = 0 then
      raise EOutOfResources.Create(SNoTimers);
end;

procedure TTimerEx.WndProc(var Msg: TMessage);
begin
  with Msg do
    if Msg = WM_TIMER then
      try
        Timer;
      except
        Application.HandleException(Self);
      end
    else
      Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;


ziolko.
 
04.15.2008 at 04:50AM PDT, ID: 21357725

Rank: Sage

awww just notied error in your code, you destroy  stringlist before event is triggered.

fixed:
procedure TTimerEx.Timer;
var
  slTemp :TStrings;
  Rec :TSearchRec;
  I :Integer;
begin
  If not Assigned(FOnTimer) then Exit;
  If not DirectoryExists(WatchFolder) then Exit;

  slTemp := TStringList.Create;
  Try
    I := FindFirst(WatchFolder + '\*.*', faAnyFile, Rec);
    While I = 0 do
    begin
      If Rec.Name[1] <> '.' then slTemp.Add(WatchFolder + '\' + Rec.Name);
      I := FindNext(Rec);
    end;
    FOnTimer(Self, slTemp);
  Finally
    slTemp.Free;
  end;
end;


ziolko.
 
04.16.2008 at 12:35AM PDT, ID: 21365513
Yup, I actually fixed that one yesterday as well.
Like I said, everything is working 100%.

Only think I would like to do now is to un-publish the OnTimer() event.
Don't want it to appear in design time.

Thanks.
 
04.16.2008 at 12:59AM PDT, ID: 21365622

Rank: Sage

>>Only think I would like to do now is to un-publish the OnTimer() event.
you don't want OnTimer at all or you want only your property with extra parameter?

ziolko.
 
04.16.2008 at 04:20AM PDT, ID: 21366470
I want my new OnTimerEx() event to work with extra parameters, and it is working.
But currently my event and the standard OnTimer() event is published runtime and designtime.
I only want my event to be published and visible in runtime & designtime.

Hope this is a bit clearer. :)
 
04.16.2008 at 04:23AM PDT, ID: 21366480

Rank: Sage

if you want only your event handler to be visible you have to use component based on TComponent not on TTimer (I've posted full code above).


ziolko.
 
04.16.2008 at 11:41AM PDT, ID: 21370722
Ok I see.

Thanks for all your help. Much appreciated!
You deserved each and every point. :)
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628