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

TreeView problem

Status
Not open for further replies.

bujin

MIS
Oct 2, 2000
144
0
0
GB
I'm attempting to add some items to a tree list and it's ****ing complicated and frustrating, so I would be extremely grateful for some assistance! :)

I am attempting to write a new Script Editor utility for the game Operation Flashpoint, and I am using the treeview control to hold the Weapons and Ammunition names in the following format:

EQUIPMENT
--Weapons & Ammunition
..--{Weapon Name}
....--{Ammo Name}
....--{Additional Ammo Name}

Each weapon type will always have at least one Ammo subnode but some may have two. (I hope BI don't add weapons that can use 3 types of ammo, cos then I'm really buggered!)

So far, I have got the weapon and ammo names stored in three arrays and have successfully loaded the Weapon names into the tree list. How the heck do I now load the ammo names in there too? I've been working on it for hours and I'm getting nowhere!!!

The problem that I have is trying to work out in the program which item index I am supposed to be using.

Anyway, here's the code I've got so far:

---
// Create the Tree List
with trvList.Items do
begin
clear;

// Add Root Nodes
add(nil, 'MISSION');
add(nil, 'COMMANDS');
add(nil, 'EQUIPMENT');

// Equipment:
TN := trvList.Items[2];
addchild(TN, 'Weapons & Ammo');
addchild(TN, 'Other');

// Read the Equipment list from the file EQUIPLIST.TXT and add
// to the tree:
TN := trvList.Items[4];
AssignFile(F, 'equiplist.txt');
Reset(F);
while not Eof(F) do
begin
Readln(F, Equip);
addchild(TN, Equip);
end;
CloseFile(F);

// Read the Weapons and Ammunition List from the file WEAPONLIST.TXT.
// Add the Weapons to the treelist and store the weapon name and
// associated ammo to arrays.
TN := trvList.Items[3];
WeapCount := 0;
AmmoCount := 0;
AssignFile(F, 'weaponlist.txt');
Reset(F);
while not eof(F) do
begin
Readln(F, TxtLn);
Weapon := Copy(TxtLn, 1, Pos(',', TxtLn) - 1);
WeapList[WeapCount] := Weapon;
addchild(TN, Weapon);
Ammo := Copy(TxtLn, Pos(',', TxtLn) + 1, Length(TxtLn) - Pos(',', TxtLn));
if Pos('|', Ammo) > 0 then
begin
Ammo2 := Copy(Ammo, Pos('|', Ammo) + 1, Length(Ammo) - Pos('|', Ammo));
Ammo := Copy(Ammo, 1, Pos('|', Ammo) - 1);
AmmoList[WeapCount] := Ammo;
Ammo2List[WeapCount] := Ammo2;
end
else
begin
AmmoList[WeapCount] := Ammo;
Ammo2List[WeapCount] := '';
end;
WeapCount := WeapCount + 1;
end;
CloseFile(F);


[NB - HERE'S WHERE IT STARTS TO GO HORRIBLY WRONG, BUT THIS IS AS CLOSE AS I CAN GET SO FAR!!!]
// Now add the ammunitions to the list.
Ind := 4;
WeapCount := 0;

for I := 1 to 10 do
begin

TN2 := trvList.Items[Ind];
if (Ammo2List[WeapCount] > '') then
begin
addchild(TN2, AmmoList[WeapCount]);
addchild(TN2, Ammo2List[WeapCount]);
AmmoCount := 2;
end
else
begin
addchild(TN2, AmmoList[WeapCount]);
AmmoCount := 1;
end;
WeapCount := WeapCount + 1;
Ind := Ind + WeapCount + AmmoCount;

end;

---

While I await your responses, I am going for a lie down. My head hurts. :)

Thanks

Gareth
 
Change

if (Ammo2List[WeapCount] > '') then

to

if (Ammo2List[WeapCount] <> '') then
 
Didn't help. It's the same thing anyway, since the array will only either contain an empty string or some text and some text is greater than no text! :)

I would load the items in at design-time, which would save a lot of hassle, but I want the program to be able to read the items in from a textfile for when the lists change, as they inevitably will in the future.
 
No, sometext > '' won't evaluate properly.

Have you tried stepping through and seeing where the problem occurs? And what exactly is the problem?
 
Doesn't matter now. I've found a much easier way around it by creating the text file as a tabbed file and using the TreeView.LoadFromFile() function.

Thanks anyway. However, I do have one small question left:

What is the Delphi version of the Visual Basic DIR() command to get a list of the files in a directory?
 
I always use &quot;FindFirst&quot;, and related functions from the SysUtils unit. Have a look in the help file for details on how to use it.

Just a note: When you get a list of files, I think you will always get back '.' and '..' as well (the current and parent directories), so check that you're working with a file, and not a directory.
 
I always use &quot;FindFirst&quot;, and related functions from the SysUtils unit. Have a look in the help file for details on how to use it.

Just a note: When you get a list of files, I think you will always get back '.' and '..' as well (the current and parent directories), so check that you're working with a file, and not a directory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top