Posted: Tue Nov 11, 2003 5:17 pm Post subject:
New utility born!
Last week's chat with iceman559 gave me another idea: a duplicate section finder/wiper. I found some free time and after 30 minutes of coding, here it is.
It's pretty stable (there aren't many chances for you to do anything wrong.. except clicking something bedfore loading INI file )
However, two notes:
1: Due to RA2/TS non-standard INI coding (allowing side-comments), standard ini parsing controls don't work properly. So I have three choices:
a) eat up user's CPU time by building a comment-free copy;
b) ask him to use INI checker to wipe the comments
c) ask him to use Wordpad/Editpad to replace all comment mark symbols with newline and comment mark.
Right now I prefer options b or c. So, get rid of the comments before using this...
2: although you choose which sections to delete, it probably deletes the first one it finds with the same name. Beware...
Anyway, enjoy!
And I'm sorry about not making an AI Randomizer as promised , but this small thing fit perfectly into my free time
Tip: to get it to delete the correct duplicate store the line number of each section so you can easily delete the correct one.
type
tsectionpos = Array of packed record
line_no : Cardinal;
end;
var
sectionpos : tsectionpos;
usage:
When loading the file
count := 0;
setlength(sectionpos,0);
for x := 0 to linesofsomething.count-1 do
if this line contains a section then
begin
count := count +1;
setlength(sectionpos,count+1);
sectionpos[count].line_no := x;
end;
When working out the location
The sectionpos number should be the same as the component you use to store the information(im guessing a ListView1)
the line number for a particular section would b something like
sectionpos[listview1.whateverisselected].line_no
Note: not everything above is actual delphi code, without correction it wouldn't work int he real world, the bits in italics are english words not delphi code
Hope this helps you.
P.S DELPHI RULZ!!!!!!
Quote:
However, two notes:
1: Due to RA2/TS non-standard INI coding (allowing side-comments), standard ini parsing controls don't work properly. So I have three choices:
a) eat up user's CPU time by building a comment-free copy;
b) ask him to use INI checker to wipe the comments
c) ask him to use Wordpad/Editpad to replace all comment mark symbols with newline and comment mark.
what do you mean?(i wonder what comments have to do with deleting duplicate sections)
imo you should add hints to the buttons so ppl know exactly what there for (arrow pointing downwards means nothing to me)
Because I'm just a beginner, I used the easiest way of INI parsing - Delphi's parsing unit INIFiles, which checks for sections this way:
read a line from file
if (S[1] = '[') and (S[Length(S)] = ']') then
add to sectionlist
Obviously, it doesn't accept comments ... I'm not skilled enough to make my own INI parser, and modifying this line in the INIFiles.pas doesn't seem to affect anything, I wonder why?
I really need to learn more about coding... I'll be looking at the whole unit today, to get some ideas about how is that parser made and try to make something similar. Thanks for your ideas, they're really helpful. QUICK_EDIT
Because I'm just a beginner, I used the easiest way of INI parsing - Delphi's parsing unit INIFiles, which checks for sections this way:
read a line from file
if (S[1] = '[') and (S[Length(S)] = ']') then
add to sectionlist
Obviously, it doesn't accept comments ... I'm not skilled enough to make my own INI parser, and modifying this line in the INIFiles.pas doesn't seem to affect anything, I wonder why?
I really need to learn more about coding... I'll be looking at the whole unit today, to get some ideas about how is that parser made and try to make something similar. Thanks for your ideas, they're really helpful.
Im guessing this is a delphi 7(i see you have the profesional version) only file, never knew it existed.(i use Delphi 4 and 6 mainly)
The way i "parse" info is like so:
if (copy(richedit1.lines.strings[x],1,1) = '[') and (copy(richedit1.lines.strings[x],length(richedit1.lines.strings[x])-1,1) = ']') then
works the same, yours is the simple way.
what do u mean you don't know how to parse comments? Lines that have a comment half way through it? Lines that start with a comment? _________________ Free Map Editor - Game Requirements - Stucuk.Net QUICK_EDIT
I use Delphi 6 too, and it's in there, in /Source/rtl/Common/inifiles.pas , just adding INIFiles to unit's Uses statement works.
I mean if a file is built like this:
Quote:
[YURI] ; yuri clone
, it'll prevent the program from adding the line to the section list. If a simple line has a comment, it doesn't matter in this case. But my INI Checker had this pain, and I didn't know any solutions, so it silently built a comment-free copy of the opened file in tem0.ini, and used it for every operation.
And about hta INIFiles unit... is it me, or do the built-in units ignore modifications? I changed the mentioned line to
if ((S[1] = '[') and (Pos(']',S)<>0)) then
... saved it, recopmpiled, but nothing changed
weird, and I don't know how to solve it. QUICK_EDIT
are there comments on the same line as section "headings" in the original RA2 / YR rules ? _________________ Free Map Editor - Game Requirements - Stucuk.Net QUICK_EDIT
btw ur modifyed line will work. Just copy the section that does the ini stuff you want to your program. _________________ Free Map Editor - Game Requirements - Stucuk.Net QUICK_EDIT
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum