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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCollection - Possible to prevent changing items in run-time?

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
0
0
US
I have a TCollection/TCollectionItem set of descendents. They are intended to be set up in Design-time only, and should never be modified in Run-time. How can I do this? Design-time should always allow whatever edits are needed, but in Run-time, I don't want to be able to Add, Remove, or Re-index any of the items in the collection. The properties of each of those items, yes, I do want them to be enabled. But changing the actual items around shall only be in design-time.

JD Solutions
 
I assume this is in a control of some kind. That given, I'd try making functions to set the values of these items and then in those functions do something like:

Code:
 if (csDesigning in ComponentState) then
   begin
//   < set values>
   end

Logically it should ignore assigning the values on run-time.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
So you mean for example...

Code:
function TMyCollection.Add: TMyCollectionItem;
begin
  if (csDesigning in ComponentState) then begin
    Result:= TMyCollectionItem(inherited Add);
    //do whatever you need to do...
  end else begin
    //Raise exception
  end;
end;

procedure TMyCollection.Delete(Index: Integer);
begin
  if (csDesigning in ComponentState) then begin
    //do whatever you need to do...
    inherited Delete(Index);
  end else begin
    //Raise exception
  end;
end;

//Etc...

Damnit, when you can start writing entire units of code in any text editor, you know you've gone deep into programming :p


JD Solutions
 
I forgot to mention my sarcastic response to my own question in my last post... Durr, I should have figured that one out **slaps self in face**

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top