Frank Wunderlich napsal(a):
Hi,
i'm trying to write a script which opens all files from a
delphi-project-file.
here a such file:
program dfmedit;
uses
Forms,
SizerControl in 'sizecontrols\SizerControl.pas',
main_u in 'main_u.pas' {Form_DFMMain},
preview_u in 'preview_u.pas' {Form_DFMPreview},
...
unit_u in 'unit_u.pas';
{$R *.RES}
begin
...
end.
as you see, i need to parse all the stuff between '' till last character
in line is ; and open this using path of the project file.
my problem doing this is getting the string between ''
here my actual script:
function openPasFromDpr()
local path = props['FileDir'] --without trailing /\
--for ln = 0, editor.LineCount - 1 do
output:append(path)
ln=0
while ln < editor.LineCount do
local lbeg = editor:PositionFromLine(ln)
local lend = editor.LineEndPosition[ln]
local text = editor:textrange(lbeg, lend)
local p1= string.find(text,'\'')
local p2= string.find(text,'\'',p1+1)
--local c1,c2,c3 = split3(text,'\'')
c2=string.sub(text,p1+1,p2-p1)
-- if c2 <> '' then
output:append(path..'/'..c2..'\n')
scite.Open(path..'/'..c2)
-- end
if text[string.len(text)] ==';' then
ln=editor.LineCount
else
ln=ln+1
end
end
end
i get a 'attempt to perform arithmetic on local `p1' (a nil value)' on
line 22.
how do i get the string between ''?
Regards Frank
This error is from parsing first line (program dfmedit), where no ' is
found, so nil is returned. I tried to change your script a bit, ended
with this:
function openPasFromDpr()
local path = props['FileDir'] --without trailing /\
--for ln = 0, editor.LineCount - 1 do
--~ output:append(path)
ln=0
while ln < editor.LineCount do
local lbeg = editor:PositionFromLine(ln)
local lend = editor.LineEndPosition[ln]
local text = editor:textrange(lbeg, lend)
local p1= string.find(text,'\'')
if p1 then
local p2= string.find(text,'\'',p1+1)
--local c1,c2,c3 = split3(text,'\'')
c2=string.sub(text,p1+1,p2-1)
-- if c2 <> '' then
output:append(path..'\\'..c2..'\n')
--~ scite.Open(path..'\\'..c2)
-- end
end
ln=ln+1
end
end
This outputted for me following:
C:\Util\scite\sizecontrols\SizerControl.pas
C:\Util\scite\main_u.pas
C:\Util\scite\preview_u.pas
C:\Util\scite\unit_u.pas
which seems to be what you want. You may also have some problems with
opening them as current file will change and you will be no longer able
to read original file.
-- Roman
_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest