Debugging / Writing to file
-
- Newbie
- Posts: 7
- Joined: Mon May 02, 2011 6:02 am
Debugging / Writing to file
Hi @all!
I searched the scritps, helpfiles and the web but couldn't find an answer to this questsions:
Is it possible to use Delphi-Units or to use godfahter-units from within delphi?
Is there a possibility to debug the scripts or to at least open, write and close a simple text-file?
Thanks for your help in advance!
Dreamweaver
I searched the scritps, helpfiles and the web but couldn't find an answer to this questsions:
Is it possible to use Delphi-Units or to use godfahter-units from within delphi?
Is there a possibility to debug the scripts or to at least open, write and close a simple text-file?
Thanks for your help in advance!
Dreamweaver
Re: Debugging / Writing to file
The scripts are standalone units, you cannot use another unit or script everything has to be included in a single script file (unit).
What do you have in mind? maybe there is another way around it
What do you have in mind? maybe there is another way around it
Dimitris
-
- Newbie
- Posts: 7
- Joined: Mon May 02, 2011 6:02 am
Re: Debugging / Writing to file
I'd like to
- use Delphi-functions/procedures like AnsiStartsStr (StrUtils unit).
- debug my script or to write values of variables to a local text file.
Right now I'd try to write a little script (almost finished) to cut of "The " from the beginning of 'artist' and to preview the behavior of the script via a logfile before the first run of that script on my library
- use Delphi-functions/procedures like AnsiStartsStr (StrUtils unit).
- debug my script or to write values of variables to a local text file.
Right now I'd try to write a little script (almost finished) to cut of "The " from the beginning of 'artist' and to preview the behavior of the script via a logfile before the first run of that script on my library

Re: Debugging / Writing to file
The easiest to write to a file is to use a TStringList, populate it with the values you want and then save to a text file, you can use TFileStream also but the stringlist is much easier.
AnsiStartsStr is not included but i could add it in the scripts, you can however use something like
or even regex
What I would recomend for this task is to use a filter (check the use tag filter checkbox , then select artist and type The in the field) that will show only the files you want in the tag grid.
After that create a simple tag script to check your artist field then update the value in the grid, no values will be saved and you can preview the results in the grid, click update when ready to save the values to your files and you are done.
AnsiStartsStr is not included but i could add it in the scripts, you can however use something like
Code: Select all
if UpperCase( Copy( sTmp, 1, 4 ) ) = 'THE ' then begin ...
What I would recomend for this task is to use a filter (check the use tag filter checkbox , then select artist and type The in the field) that will show only the files you want in the tag grid.
After that create a simple tag script to check your artist field then update the value in the grid, no values will be saved and you can preview the results in the grid, click update when ready to save the values to your files and you are done.
Dimitris
-
- Newbie
- Posts: 7
- Joined: Mon May 02, 2011 6:02 am
Re: Debugging / Writing to file
TStringList looks interesting! I'll check that out during the next days, right now I don't have access to my little machine at home.
Don't wast time to include AnsiStartsStr. I was just wondering which Delphi-functions are available. Is there a little README somewhere to get a hint which Delphi-functions and classes can be used?
I indeed am working with the filter you suggest ... 'cuz I think there is no undo on the script operations, I'm a lilttle bit afraid to make 'unknown' changes to the library database (yes, yes, yes, I can save it to the files first an then reread it from the tags again in case of misbehavior of my script
) ).
Cheers and thanks a lot so far!! I'll compile a little success story when I'm done.
Don't wast time to include AnsiStartsStr. I was just wondering which Delphi-functions are available. Is there a little README somewhere to get a hint which Delphi-functions and classes can be used?
I indeed am working with the filter you suggest ... 'cuz I think there is no undo on the script operations, I'm a lilttle bit afraid to make 'unknown' changes to the library database (yes, yes, yes, I can save it to the files first an then reread it from the tags again in case of misbehavior of my script

Cheers and thanks a lot so far!! I'll compile a little success story when I'm done.
-
- Newbie
- Posts: 7
- Joined: Mon May 02, 2011 6:02 am
Re: Debugging / Writing to file
Hmm, doesn't really work. Seems it's not allowed to define a TStringList-object.
When I I do something like ...
// -------- begin -------
10 var
11 sTmp: string;
...
13 out: TStringList;
14
15 begin
16 out:= TStringList.Create;
...
// -------- end -------
... then the script interpreter says:
Compiler: [Error](13:5): 'BEGIN' expected
Any help?
When I I do something like ...
// -------- begin -------
10 var
11 sTmp: string;
...
13 out: TStringList;
14
15 begin
16 out:= TStringList.Create;
...
// -------- end -------
... then the script interpreter says:
Compiler: [Error](13:5): 'BEGIN' expected
Any help?
Re: Debugging / Writing to file
Can you post the entire srcipt please, mybe the directive Program ; is missing
Dimitris
-
- Newbie
- Posts: 7
- Joined: Mon May 02, 2011 6:02 am
Re: Debugging / Writing to file
It works like a charme now. Defining a variable named 'out' was probably not a very smart thing. I'm away from Delphi for some time now, but remembering basic C++ they have an out-stream class. And Delphi seems to have at least a reserved token 'out'. Nevertheless, renaming 'out' to something else did it.
program Remove_The;
var
sTmp: string;
bUpdated: boolean;
bTest: boolean;
scriptLogMode : boolean;
scriptLog: TStringList;
begin
// no rows get out
if not tg_Init then exit;
//switch scriptLogMode on (true) or off (false)
scriptLogMode := true;
//Create TStringList-Object for script activity logging
if scriptLogMode then begin
scriptLog := TStringList.Create;
scriptLog.Text := '';
end;
repeat
bUpdated := false;
sTmp := tg_GetField( 'Artist' );
if sys_RegexFind(sTmp, '(^The\s\w*)') then begin
Delete(sTmp, 1, 4)
if scriptLogMode then begin
scriptLog.Append(sTmp);
end;
if not scriptLogMode then begin
tg_setField( 'Artist', sTmp );
end;
bUpdated := true;
end;
if bUpdated then begin
tg_setSkip (false );
tg_SetResult( 'OK' );
end else begin
tg_setSkip( true );
end;
until not tg_Skip;
if scriptLogMode then begin
scriptLog.Append('=======Finished======');
scriptLog.SaveToFile('log.txt');
scriptLog.Free;
end;
end.
program Remove_The;
var
sTmp: string;
bUpdated: boolean;
bTest: boolean;
scriptLogMode : boolean;
scriptLog: TStringList;
begin
// no rows get out
if not tg_Init then exit;
//switch scriptLogMode on (true) or off (false)
scriptLogMode := true;
//Create TStringList-Object for script activity logging
if scriptLogMode then begin
scriptLog := TStringList.Create;
scriptLog.Text := '';
end;
repeat
bUpdated := false;
sTmp := tg_GetField( 'Artist' );
if sys_RegexFind(sTmp, '(^The\s\w*)') then begin
Delete(sTmp, 1, 4)
if scriptLogMode then begin
scriptLog.Append(sTmp);
end;
if not scriptLogMode then begin
tg_setField( 'Artist', sTmp );
end;
bUpdated := true;
end;
if bUpdated then begin
tg_setSkip (false );
tg_SetResult( 'OK' );
end else begin
tg_setSkip( true );
end;
until not tg_Skip;
if scriptLogMode then begin
scriptLog.Append('=======Finished======');
scriptLog.SaveToFile('log.txt');
scriptLog.Free;
end;
end.
Re: Debugging / Writing to file
Good to hear , i miised the naming also out is a reserved word, (you could use a dialog box to ask for the debug mode but thats up to you)
Dimitris
-
- Newbie
- Posts: 7
- Joined: Mon May 02, 2011 6:02 am
Re: Debugging / Writing to file
Hi Dimitris,
debug mode ? Could leave a few lines on that, how do I ask for that dialog box?
debug mode ? Could leave a few lines on that, how do I ask for that dialog box?
Re: Debugging / Writing to file
There are 3 types of dialog windows you can use, more info about parameters is on the help file.
As for debug mode , its currently not in my immediate plans but will have a look in to it in the future
Code: Select all
function sys_MessageDlg( const sMsg: string; iDlgTypeFlg,iButtonsFlg: integer ): integer;
function sys_SaveFileDialog( const sFilter, sInitialDir: string ): string;
function sys_OpenFileDialog( const sFilter, sInitialDir: string ): string;
As for debug mode , its currently not in my immediate plans but will have a look in to it in the future
Dimitris