Solved

SetLength and pointers

Posted on 2003-10-30
4
366 Views
Last Modified: 2012-05-04
I'll try and confuse everyone as little as possible here.

I have a record. It is called email_info. This record is basically an e-mail account.
I have email_accounts which is an array of email_info.

I add new accounts to a list (similar to a treeview i guess.) when the user mouses over, they see a tooltip (hint) containting data from that account. i.e. new messages, etc..

Problem. When I add a new record (account) I call SetLength(email_accounts, Length(email_accounts) +1)

this moves my array to a different location in memory. so when i add a new account, the accounts above it don't know where to grab their data. so i usually get some funky stuff in there.

what would solve this? a pointer to the pointer that's already in the tooltip?

this is probably VERY confusing, sorry :)
0
Comment
Question by:gwarguitar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
j42 earned 75 total points
ID: 9656238
I can see two ways:

1. Don't store the address of your record but the index in the array instead
2. Don't use records at all. Define a class to store your email info and
   use a TObjectList as container.
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9656314
Hi,

I basically second j42 here, but I would add some insight on the matter.

First of all, we've no clue of the record structure( yes, it matters ) and I
think you're using LongStrings in it, right? <g>

If I was you, in order to have a safe move, I'd do this:

procedure ExpandEmailArray( SrcArr : array of TEmailInfo;Delta : Integer;var DstArr : array of TEmailInfo );

var SrcLen : Integer;
      Elem_Idx : Integer;
begin
   SrcLen := Length( SrcArr );
   SetLengthDstArr( DstArr,Delta );
   for Elem_Idx := 0 to Pred( SrcLen ) do
   begin
      DstArr[ Elem_Idx ] := SrcArr[ Elem_Idx ];
   end;
end;

Anyway, an OO approach would definitely better.

HTH,

Andrew
0
 

Author Comment

by:gwarguitar
ID: 9679659
1. Don't store the address of your record but the index in the array instead

that put me on the right track, thanks, guys.
0
 
LVL 2

Expert Comment

by:j42
ID: 9679759
You're welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question