trouble with callback on matrix input
Posted: 02 Nov 2024, 19:39
I have a script that aims to display matrix data in columns. It works fine for the text of the cells, but I recently tried to use it to reorder the cells values, and I'm having trouble with the array ins and outs.
Basically the output array only changes if the first item in the input array changes. I don't know why.. It sets the output array correctly for all items, but only when the first value in the input array has changed.
Thanks
Thanks,
-eric
Basically the output array only changes if the first item in the input array changes. I don't know why.. It sets the output array correctly for all items, but only when the first value in the input array has changed.
Thanks
Code: Select all
//////////////////////////////////////////////////////
// read matrix data newspaper style in columns
//e moon Nov 2022
////////////////////////////////////////////////////
const FAVTAG = '-';
var rowsIN, colsIN,ctIN,valsIN : Tparameter;
var ctOUT,dispCtOUT,valsOUT: Tparameter;
var gTextin, gTextOut, gDisplayText : TstringList;
var row, col : integer;
// Globally enable/disable logging///////////////////////////////////////
const DTAG = 'matrix Sw> ';
const DBUG_ON = TRUE;
procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;
procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;
procedure fDebug(s: string; num : single); begin debug(s + '= ' + floatToStr(num)); end;
// Always log, whether debug is on or not.
procedure Error(s: string); begin strace('ERROR-' + DTAG + s); end;
procedure fError(s: string; num : single); begin strace('ERROR-' + DTAG + s + '= ' + floatToStr(num)); end;
//////////////////////////////////////////////////////////////////////////
procedure init;
begin
colsIN := CreateParam('col ct',ptDatafield,pioInput);
rowsIN := CreateParam('row ct',ptDatafield,pioInput);
ctIN := CreateParam('ctext',ptTextField,pioInput);
valsIN := CreateParam('values',ptArray,pioInput);
ctOUT := CreateParam('ct out',ptTextField,pioOutput);
dispCtOUT := CreateParam('display ct',ptTextField,pioOutput);
valsOUT := CreateParam('values out',ptArray, pioOutput);
ModuleColor($FF8E44AD);
gTextin.create; gTextOut.create; gDisplayText.create;
end;
// destroy
procedure Destroy; begin gTextIn.free; gTextOut.free; gDisplayText.free; end;
procedure Callback(n:integer);
var i,j,len: integer;
var val: float;
var text,displayT: string;
var options: TReplaceFlags;
VAR values : ARRAY OF float;
begin
//setArrayLength(values, 0);
//if n = valsIN then
//begin
len := valsIN.Length;
valsOUT.Length(len);
debug('vals in changed');
j := 0;
for col := 0 to (colsIN.asInteger - 1) do
begin
for row := 0 to (rowsIN.asInteger - 1) do
begin
i := (colsIN.asInteger * row) + col;
valsOUT.asArray(j,valsIN.asArray(i));
//values[j] := valsIN.asArray(i));
//iDebug('setting output array position',j);
//iDebug('to value',i);
j := j + 1;
end;
end;
gTextIn.clear; gTextOut.clear; gDisplayText.clear;
gTextIn.setCommaText(ctIN.asString);
options := [];
for row := 0 to (rowsIN.asInteger - 1) do
begin
for col := 0 to (colsIN.asInteger - 1) do
begin
i := (rowsIN.asInteger * col) + row;
if i >= gTextIn.count then text := '' else text := gTextIn.getStrings(i);
gTextOut.add(text);
//trim leading '-' from names for display
if text.startsWith(FAVTAG) then displayT := StringReplace(text, FAVTAG,'', options) else displayT := text;
gDisplayText.add(displayT);
j := j + 1;
end;
end;
ctOUT.asString(gTextOut.GetCommatext);
dispCtOUT.asString(gDisplayText.GetCommatext);
//end;
end;
-eric