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!

create()-probs

Status
Not open for further replies.

sancho1980

Technical User
Nov 25, 2005
15
0
0
DE
Hello people,
as I said, I'm new to Pascal but what I'm encountering now really goes beyond my capacities. What I'm trying to do in the following snippet is simply create objects of my own TEntry class and then insert them into a TList but it seems like every time I invoke Create I get the same pointer back, so in the end I'm creating only one object!!! Have a look at this one:

var
p: Pointer;
i: Integer;
content: TStrings;
entry: TEntry;
begin
p := nil;
content := TStringList.Create();
content.LoadFromFile(FileName);
if content.Count mod 2 = 0 then
begin
i := 0;
while i < content.Count do
begin
entry := TEntry.Create();
if p = Addr(entry) then
ShowMessage('Same address!!!');
//some instruction
Inc(i);
//some instruction
Inc(i);
self.Add(Addr(entry));
p := Addr(entry);
end;
...

If you execute that in a program you always get the 'Same address!!!' message. This is not what I intend. I obviously intend to create content.Count/2 objects and have them all added to my list. What is wrong with that code??? Please help,
best,
Martin
 
From the nature of the questions you are asking, it seems as if you are in the wrong group. You are using Delphi, not Pascal.

Please go here for your Delphi questions: You will likely find more people that will be willing/able to answer your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top