Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #11  
Old 12-11-2015, 12:46 PM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

take note the edit cannot read the label
Reply With Quote
  #12  
Old 12-12-2015, 08:55 AM
Merovingio Merovingio is offline
Member
 
Join Date: Jun 2015
Posts: 30
Default

Hi I have add two properties TEventType and Separator. At DesignTime all ok bat If change default values at runtime is generated from debugger a error Property non found!

unit FireEvent;

interface

uses
System.Classes;

type

TEventType = ( ttNone, ttVar, ttCmd, ttFirst, ttEnd );

TOnCommand = procedure (Sender: TObject; ACommand: String) of object;

TEventItem = class (TCollectionItem)
private
FCaption: string;
FSeparator: string;
FOnCommand : TOnCommand;
FEventType : TEventType;
protected
procedure SetCaption(const Value: string);
procedure SetSeparator(const Value: string);
published
property EventType: TEventType read FEventType write FEventType default ttNone;
property Caption: string read FCaption write SetCaption;
property Separator : string read FSeparator write FSeparator;
property OnCommand : TOnCommand read FOnCommand write FOnCommand;
end;

TEventCollection = class (TCollection)
private
FComp: TComponent;
public
constructor Create (CollOwner: TComponent);
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
function Parse(Char, S: string; Count: Integer): string;
function FireEvent(Text : string) : boolean;
end;


TFireEvent = class(TComponent)
private
FColl: TEventCollection;
procedure SetEvents(const Value : TEventCollection);
protected
{ Protected declarations }
public
constructor Create (aOwner : TComponent); override;
destructor Destroy; override;
published
property Events : TEventCollection read FColl write SetEvents;
end;

procedure Register;

implementation

{$R 'FireEvent.dcr'}

procedure Register;
begin
RegisterComponents('Support', [TFireEvent]);
end;

constructor TFireEvent.Create (aOwner : TComponent);
begin
inherited;
FColl := TEventCollection.Create(self);
end;

destructor TFireEvent.Destroy;
begin
FColl.Free;
inherited;
end;

procedure TFireEvent.SetEvents(const Value : TEventCollection);
begin
FColl.Assign(Value);
end;

procedure TEventItem.SetCaption(const Value: string);
begin
FCaption := Value
end;

procedure TEventItem.SetSeparator(const Value: string);
begin
FSeparator := Value
end;

constructor TEventCollection.Create (CollOwner: TComponent);
begin
inherited Create (TEventItem);
FComp := CollOwner;
end;

function TEventCollection.GetOwner: TPersistent;
begin
Result := FComp;
end;

procedure TEventCollection.Update(Item: TCollectionItem);
var
str: string;
i: Integer;
begin
inherited;
str := '';
for i := 0 to Count - 1 do
begin
str := str + (Items [i] as TEventItem).Caption;
if i < Count - 1 then
str := str + '-';
end;
end;

function TEventCollection.FireEvent(Text : string) : boolean;
var
i: Integer;
begin
for i := 0 to Count - 1 do
begin
if Parse(' ',Text,1) = (Items [i] as TEventItem).Caption then
begin
if assigned((Items [i] as TEventItem).OnCommand) then
begin
(Items [i] as TEventItem).OnCommand(self,Parse(' ',Text,2));
Result := true;
exit;
end;
end;
end;
Result := false;
end;

function TEventCollection.Parse(Char, S: string; Count: Integer): string;
var
I: Integer;
T: string;
begin
if Length(S) = 0 then exit;

if S[Length(S)] <> Char then
S := S + Char;
for I := 1 to Count do
begin
T := Copy(S, 0, Pos(Char, S) - 1);
S := Copy(S, Pos(Char, S) + 1, Length(S));
end;
Result := T;
end;
Reply With Quote
  #13  
Old 12-13-2015, 08:40 AM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

You have basic understanding
but now you have to debug in run time and then use it in design time

You can see what you ask is a lot of hassle to achieve, that next time you will think about how to create your code.

Best regards
Reply With Quote
  #14  
Old 12-16-2015, 07:59 AM
Merovingio Merovingio is offline
Member
 
Join Date: Jun 2015
Posts: 30
Default

I not want debug anything.
When application start display exception.
Reply With Quote
  #15  
Old 12-16-2015, 11:37 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

Quote:
I not want debug anything.
What a comment, hope you're not serious
Not wanting to debug is equal to not want to write code

Happy-flow is fun, but at any given point you'll run into an error you'll have to debug and see where (and why) you run into that error
Debugging is nobody's favourite hobby, but necessary

If I would see what the error raises I would use the debugger, basically the same steps you're supposed to do now

So good luck with debugging
Reply With Quote
  #16  
Old 12-16-2015, 09:13 PM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

Totally agree, The lessons learned hear can get used with TCollection and TCollection item descendants too, and sorts the boys from the men that can do real OOP.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:07 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.