Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 2nd, 2013, 07:37 PM
userage userage is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 userage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 12 sec
Reputation Power: 0
Component Creation at Runtime

I am creating a component at runtime but i am having an issue because when I create 2 of these components, I would change the value of the properties on one of them but it seems to also change it on the other.

How can I create components at runtime so they are seperate components and not instances of eachother?

Thanks,

Code Ive got so far

Code:
Cell[CellCount]:= TBattery.Create(nil);
Cell[CellCount].Top := Random(500);
Cell[CellCount].Left := Random(500);
Cell[CellCount].Parent := Self;
Cell[CellCount].ID := CellCount;
CellCount := CellCount + 1;

Reply With Quote
  #2  
Old March 26th, 2013, 11:45 AM
emailx45 emailx45 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 44 emailx45 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 7 m 32 sec
Reputation Power: 5
Thumbs up

When using CREATE( OWNER ) parameter, the OWNER will be who will delete the new component. When using NIL, will be you who delete. When using SELF, usually, will be "the FORM", or, another container (FORM, FRAME, DATAMODULE, PANEL, etc...)
--------------------------------------

var
xCmpTmp:TButton;
begin
try
try
xCmpTmp := TButton.create;
xCmpTmp.propertyXXXX := valueXXXXX;
except
... exception control here
end;
finally

{ if Assigned(xCmpTmp) then FreeAndNil(xCmpTmp); // if dont need more }

end;

if Needs of the component in another place in your software, MAKE IT not in a handler event, procedures, functions etc... MAKE IT in a place BEFORE use it and DELETE it in another place

example:

1 - make it before called the forms that using it
2 - erase (free) it after all use this components.

You can use a ARRAY for stored your components:

var
xCmpTmpArray:Array[0..10] of TButton;

....
xCmpTmpArray[0] := TButton.Create;

For use one "OPEN ARRAY" ( xCmpTmpArray:Array of TButton) you need one code more complex to control "what" will deleted.

Making components in RunTime
http://delphi.about.com/od/kbcurt/a/dynamiccreation.htm

Last edited by emailx45 : March 26th, 2013 at 11:49 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Component Creation at Runtime

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap