Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2009, 12:07 PM
JR-ZS JR-ZS is offline
Junior Member
 
Join Date: Jan 2009
Posts: 2
Default Pointers and TList

Hello.

First I would like to say that I am new to Delphi, and that this is my first project with the language. I am using Delphi 2005 on Windows XP Pro.

I currently have a form with many check, list, and spin boxes. I need to create options for saving the current 'position' of these items (Checked, ItemIndex, Value -respectively) to a file for loading later.

Because there are quite a few of these components, I wanted to find a way to dump them into a list and iterate over them, thereby grabbing the needed information.

I have attempted to create a TList, assigning a pair of objects to it, and then using pointers to grab the objects from the list to determine the values of their properties.

Unfortunately I get no errors, just an unexpected result. I always get the same value (in this case -.Checked = true) regardless of the object's state. What follows is the current code I am testing with. (to be expanded upon once I get it functioning properly)

Thanks in advance for the help. I hope I explained myself clearly enough!

[delphi]var
objects: TList;
pChk: ^TbsSkinCheckRadioBox;
tmpChk: TbsSkinCheckRadioBox;
begin
objects := TList.Create;
objects.Add(chkPostal);
objects.Add(chkTel);

pChk := objects.Items[0];
tmpChk := pChk^;

if tmpChk.Checked then
lblRecordsFound.Caption := 'checked!'
else
lblRecordsFound.Caption := 'not checked';[/delphi]
Reply With Quote
  #2  
Old 01-13-2009, 02:56 PM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: Pointers and TList

[DELPHI]
var
objects: TList;
// pChk: ^TbsSkinCheckRadioBox; //you don't really need this
tmpChk: TbsSkinCheckRadioBox;
begin
objects := TList.Create;
objects.Add(chkPostal); // assuming this is a TbsSkinCheckRadioBox
objects.Add(chkTel);

// pChk := objects.Items[0]; //Items is the default property so you don't need
//to specify it

tmpChk := TbsSkinCheckRadioBox( objects[0] ); //just typecast the list's pointer

if tmpChk.Checked then
lblRecordsFound.Caption := 'checked!'
else
lblRecordsFound.Caption := 'not checked';

[/DELPHI][pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
  #3  
Old 01-14-2009, 05:41 AM
JR-ZS JR-ZS is offline
Junior Member
 
Join Date: Jan 2009
Posts: 2
Default RE: Pointers and TList

Wonderful, this is exactly what I needed! As usual, I was over-complicating things.

Thank you very much.
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 On

Forum Jump


All times are GMT. The time now is 10:43 AM.


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