Page 1 of 1
Posted: 03 Mar 2011, 15:26
by ethnix73
I'm trying to modify the get commatext element script, to obtain the inverse result: remove an element from commatext.
I just want to get an element from a commatext, and remove it. The goal is to get the commatext from a list box, and being able to remove the selected element from the list.....
Any script guru who could help me?
Posted: 03 Mar 2011, 15:31
by ethnix73
Oups, the script:
/////////////////////////////////////////////
// Get Comma text element
////////////////////////////////////////////
// parameters declaration
var input : Tparameter;
var nth : Tparameter;
var output : Tparameter;
var sl1 : TStringList;
// destroy
procedure Destroy;
begin
sl1.free;
end;
// initialisation : create parameters
procedure init;
begin
SetModuleColor($808080+302060);
Input := CreateParam('in',ptTextField);
SetIsOutPut(Input,false);
nth := CreateParam('num',ptdataField);
SetIsOutPut(nth,false);
SetMin(nth,0);
SetMax(nth,MAXINT);
SetFormat(nth,'%.0f');
output := CreateParam('out',ptTextField);
SetIsInPut(Output,false);
Sl1 := TStringList.Create;
end;
procedure Callback(n:integer);
var idx : integer;
var result : string;
begin
Sl1.CommaText := GetStringValue(Input);
idx := round(GetValue(nth));
if (idx>=0)
and (idx<SL1.count)
then result := SL1.Strings[idx]
else result := '';
SetStringValue(Output,result);
// strace(GetStringValue(outPut));
end;
// no process bloc
Posted: 03 Mar 2011, 15:46
by bsork
I haven't tested it myself (at least not that I can remember), but after getting the input string and index I think you can try something like:
Code: Select all
Sl1.Delete(idx);
SetStringValue(Output, Sl1.CommaText);
Posted: 03 Mar 2011, 16:39
by ethnix73
Yes, thanks master bsork!
I tried
delete but i have yet big difficulties with script syntax....
So, here is the good script for "Remove commatext elt":
/////////////////////////////////////////////
// Remove Comma text element
////////////////////////////////////////////
// parameters declaration
var input : Tparameter;
var nth : Tparameter;
var output : Tparameter;
var sl1 : TStringList;
// destroy
procedure Destroy;
begin
sl1.free;
end;
// initialisation : create parameters
procedure init;
begin
SetModuleColor($808080+302060);
Input := CreateParam('in',ptTextField);
SetIsOutPut(Input,false);
nth := CreateParam('num',ptdataField);
SetIsOutPut(nth,false);
SetMin(nth,0);
SetMax(nth,MAXINT);
SetFormat(nth,'%.0f');
output := CreateParam('out',ptTextField);
SetIsInPut(Output,false);
Sl1 := TStringList.Create;
end;
procedure Callback(n:integer);
var idx : integer;
var result : string;
begin
Sl1.CommaText := GetStringValue(Input);
idx := round(GetValue(nth));
if (idx>=0)
and (idx<SL1.count)
then Sl1.Delete(idx);
SetStringValue(Output, Sl1.CommaText);
// strace(GetStringValue(outPut));
end;
// no process bloc
Posted: 04 Mar 2011, 13:12
by bsork
Sorry, but I guess could've been more spesific in telling where to place the code. I does work, though. A tip if you want the commatext sometimes to be copied in to out is to use an nth value of eg -1 and add the needed IF test.
Posted: 06 Mar 2011, 12:38
by ethnix73
The script is ok for my need, bsork.
Thanks anyway.