Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating First Component!

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
This is a follow up thread to Thread102-940336. Thanks to Andrew & Clive, I'm attempting to create my first component (TScrollStringGrid).

I have read Andrew's FAQ and I'm also reading 'Introduction to Component Building'.

Now I need a little guidance in deciding what my component should do!! I obviously need it to scroll (duh!), so how do I add the timer to the component? Does TScrollStringGrid need to inherit that component as well? How do I do that?

Since I get to design this from scratch, I would also like to specify the number of lines it scrolls each time. I'm pretty sure that's possible?? [ponder]

Any pointers GREATLY appreciated!

Les


 
You don't inherit from it, you include it in your component. If the timer will be accessed from outside of your component, you can make the timer a property or you can, instead, make the timer settings properties and use the write/set part of the property definition to set the specific properties of the timer. Also, your component will be responsible for creating and destroying the timer.

Your code might look something like this:
Code:
Interface
  TScrollStringGrid: class(TStringGrid);
  ...
  private
    fTimer: TTimer;
    procedure SetTimerInterval(value: Cardinal);
    ...
  published
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property TimerInterval Cardinal write SetTimerInterval;
    ...
  end;

implementation

constructor TScrollStringGrid.Create(AOwner: TComponent);
begin
  inherited;
  ...
  fTimer := TTimer.Create(Self);
end;

destructor TScrollStringGrid.Destroy;
begin
  fTimer.Free;
  ...
  inherited;
end;
...

procedure TScrollStringGrid.SetTimerInterval(value: Cardinal);
begin
  fTimer.Interval := value;
end;
...
-Dell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top