Statistics: Posted by woodslanding — 28 Aug 2013, 21:44
CODE:
function split_string(const sep, str: string) : array of string; // {{{2var i, start, cnt, endpos, seplen: integer;begin if (str = '') thenbeginSetArrayLength(Result, 0);Exit;end;if (sep = '') thenbeginSetArrayLength(Result, 1);Result[0] := str;Exit;end;seplen := Length(sep);SetArrayLength(result, (Length(str) div seplen) + 1);i := 1;start := i;cnt := 0;while (i <= (Length(str) - seplen + 1)) dobeginif (str[i] = sep[1]) thenif (Copy(str, i, seplen) = sep) thenbeginif (start < i) thenResult[cnt] := Copy(str, start, i - start)elseResult[cnt] := '';Inc(cnt);Inc(i, seplen - 1);start := i + 1;end;Inc(i);end;endpos := Length(str) + 1;if (start < endpos) thenResult[cnt] := Copy(str, start, endpos - start)elseResult[cnt] := '';Inc(cnt);SetArrayLength(Result, cnt);end;Statistics: Posted by ynohtna — 20 Aug 2013, 21:34
Statistics: Posted by woodslanding — 20 Aug 2013, 01:09
Statistics: Posted by ynohtna — 18 Aug 2013, 17:47
Statistics: Posted by woodslanding — 17 Aug 2013, 17:31
CODE:
////////////////////////////////////////////////////////////////////////////////////////////////CONST BUTTON_COUNT = 32; //should be a multiple of page countCONST PAGE_COUNT = 8;VAR cellsOUT, namesOUT, presetOUT, presetsIN, pagesIN, clickedIN, presetIN: tParameter;VAR pages, presets,buttonNames : TStringList;var page, preset, presetCount, pageMax, ROW_COUNT, COL_COUNT, MATRIX_SIZE : integer; // destroyprocedure Destroy;begin pages.free; presets.free; buttonNames.free;end; PROCEDURE Init;BEGIN pagesIN := CreateParam('pages', ptTextfield); SetIsOutput(pagesIN, FALSE); presetsIN := CreateParam('presets', ptTextfield); SetIsOutput(presetsIN, FALSE); clickedIN := CreateParam('last clicked', ptDatafield); SetIsOutput(clickedIN, FALSE); presetIN := CreateParam('preset num', ptDatafield); SetIsOutput(presetIN, FALSE); cellsOut := CreateParam('cells out', ptArray); SetIsInput(cellsOut, FALSE); namesOut := CreateParam('captions out', ptTextfield); SetIsInput(namesOut, FALSE); presetOut := CreateParam('preset out', ptDatafield); SetIsInput(presetOut, FALSE); MATRIX_SIZE := PAGE_COUNT + BUTTON_COUNT; COL_COUNT := BUTTON_COUNT div PAGE_COUNT; ROW_COUNT := PAGE_COUNT; setLength(cellsOUT, MATRIX_SIZE ); pages.Create; presets.Create; buttonNames.Create; END; // Init///////////////////////////////////////////////////////////////////////////////////////// to switch rows and columns. x = row, y = col. For x = 0, add the page name. then// for x = 1 to 4, get items 0, 8, 16, and 24. that's page_count * (x-1) + y//procedure UpdateButtons;var col,row,index : integer;begin buttonNames.Clear; for row := 0 to (ROW_COUNT - 1) do begin // for each row for col := 0 to COL_COUNT do begin // for each column--incl page column if col = 0 then buttonNames.add(pages.getStrings(row)) // add page row item else begin index := (PAGE_COUNT * (col - 1)) + row; // get the row/col adjusted index.... if ((page * BUTTON_COUNT) + index) >= presetCount then begin buttonNames.add('---'); end else begin buttonNames.add(presets.getStrings((page * BUTTON_COUNT) + index)); end; end; end; end; setStringValue(namesOUT, buttonNames.getCommatext);end;PROCEDURE clearMatrix(); //////////////////CLEAR MATRIX//////////////////// var i : integer;BEGIN for i := 0 to (MATRIX_SIZE - 1) DO BEGIN setDataArrayValue(cellsOUT,i,0); strace('cell zeroed: ' + intToStr(i)); END;END; PROCEDURE enable(index : integer); /////////////////ENABLE////////////////////////BEGIN setDataArrayValue(cellsOUT, index, 1.0);END;PROCEDURE PageChanged(); /////////////////////PAGE CHANGED////////////////var index, cellNum: integer;BEGIN UpdateButtons(); ClearMatrix(); enable(page * (COL_COUNT + 1)); if (preset div BUTTON_COUNT) = page then // if the preset is on the current page.... BEGIN index:= preset mod BUTTON_COUNT; // raw preset index cellNum:= ((index mod ROW_COUNT) * (COL_COUNT + 1)) + 1 + (index div ROW_COUNT);// actual cell num enable(cellNum); END; END;PROCEDURE PresetChanged(); /////////////////////PRESET CHANGED////////////////var index, cellNum: integer;BEGIN page:= preset div BUTTON_COUNT; // figure out which page the preset is on // strace('page = ' + intToStr(page)); PageChanged(); setValue(presetOUT, preset);END;PROCEDURE Callback(n : Integer); ///////////////////////CALLBACK//////////////// VAR i, x, y, index, clicked, cellNum, column : Integer; BEGIN CASE n of presetsIN: BEGIN presets.setCommaText(GetStringValue(presetsIN)); presetCount:= presets.count; END; pagesIN: BEGIN pages.setCommaText(GetStringValue(pagesIN)); END; presetIN: BEGIN preset:= trunc(getValue(presetIN)); PresetChanged(); END; clickedIN: BEGIN cellNum:= trunc(getValue(clickedIN)); column := cellNum mod (COL_COUNT + 1); if (column = 0) then BEGIN // it's a page number page := cellNum div (COL_COUNT + 1); PageChanged(); END ELSE BEGIN index:= (column * ROW_COUNT) + (cellNum div (COL_COUNT + 1)) - ROW_COUNT;// + ROW_COUNT; preset:= (BUTTON_COUNT * page) + index; // compute preset number PresetChanged(); END; END; END; //case END; // Callback///////////////////////////////////////////////////////////////////////////////////////PROCEDURE Process;BEGINEND;Statistics: Posted by woodslanding — 10 Aug 2013, 07:57
Statistics: Posted by woodslanding — 28 Aug 2013, 21:44
CODE:
function split_string(const sep, str: string) : array of string; // {{{2var i, start, cnt, endpos, seplen: integer;begin if (str = '') thenbeginSetArrayLength(Result, 0);Exit;end;if (sep = '') thenbeginSetArrayLength(Result, 1);Result[0] := str;Exit;end;seplen := Length(sep);SetArrayLength(result, (Length(str) div seplen) + 1);i := 1;start := i;cnt := 0;while (i <= (Length(str) - seplen + 1)) dobeginif (str[i] = sep[1]) thenif (Copy(str, i, seplen) = sep) thenbeginif (start < i) thenResult[cnt] := Copy(str, start, i - start)elseResult[cnt] := '';Inc(cnt);Inc(i, seplen - 1);start := i + 1;end;Inc(i);end;endpos := Length(str) + 1;if (start < endpos) thenResult[cnt] := Copy(str, start, endpos - start)elseResult[cnt] := '';Inc(cnt);SetArrayLength(Result, cnt);end;Statistics: Posted by ynohtna — 20 Aug 2013, 21:34
Statistics: Posted by woodslanding — 20 Aug 2013, 01:09
Statistics: Posted by ynohtna — 18 Aug 2013, 17:47
Statistics: Posted by woodslanding — 17 Aug 2013, 17:31
CODE:
////////////////////////////////////////////////////////////////////////////////////////////////CONST BUTTON_COUNT = 32; //should be a multiple of page countCONST PAGE_COUNT = 8;VAR cellsOUT, namesOUT, presetOUT, presetsIN, pagesIN, clickedIN, presetIN: tParameter;VAR pages, presets,buttonNames : TStringList;var page, preset, presetCount, pageMax, ROW_COUNT, COL_COUNT, MATRIX_SIZE : integer; // destroyprocedure Destroy;begin pages.free; presets.free; buttonNames.free;end; PROCEDURE Init;BEGIN pagesIN := CreateParam('pages', ptTextfield); SetIsOutput(pagesIN, FALSE); presetsIN := CreateParam('presets', ptTextfield); SetIsOutput(presetsIN, FALSE); clickedIN := CreateParam('last clicked', ptDatafield); SetIsOutput(clickedIN, FALSE); presetIN := CreateParam('preset num', ptDatafield); SetIsOutput(presetIN, FALSE); cellsOut := CreateParam('cells out', ptArray); SetIsInput(cellsOut, FALSE); namesOut := CreateParam('captions out', ptTextfield); SetIsInput(namesOut, FALSE); presetOut := CreateParam('preset out', ptDatafield); SetIsInput(presetOut, FALSE); MATRIX_SIZE := PAGE_COUNT + BUTTON_COUNT; COL_COUNT := BUTTON_COUNT div PAGE_COUNT; ROW_COUNT := PAGE_COUNT; setLength(cellsOUT, MATRIX_SIZE ); pages.Create; presets.Create; buttonNames.Create; END; // Init///////////////////////////////////////////////////////////////////////////////////////// to switch rows and columns. x = row, y = col. For x = 0, add the page name. then// for x = 1 to 4, get items 0, 8, 16, and 24. that's page_count * (x-1) + y//procedure UpdateButtons;var col,row,index : integer;begin buttonNames.Clear; for row := 0 to (ROW_COUNT - 1) do begin // for each row for col := 0 to COL_COUNT do begin // for each column--incl page column if col = 0 then buttonNames.add(pages.getStrings(row)) // add page row item else begin index := (PAGE_COUNT * (col - 1)) + row; // get the row/col adjusted index.... if ((page * BUTTON_COUNT) + index) >= presetCount then begin buttonNames.add('---'); end else begin buttonNames.add(presets.getStrings((page * BUTTON_COUNT) + index)); end; end; end; end; setStringValue(namesOUT, buttonNames.getCommatext);end;PROCEDURE clearMatrix(); //////////////////CLEAR MATRIX//////////////////// var i : integer;BEGIN for i := 0 to (MATRIX_SIZE - 1) DO BEGIN setDataArrayValue(cellsOUT,i,0); strace('cell zeroed: ' + intToStr(i)); END;END; PROCEDURE enable(index : integer); /////////////////ENABLE////////////////////////BEGIN setDataArrayValue(cellsOUT, index, 1.0);END;PROCEDURE PageChanged(); /////////////////////PAGE CHANGED////////////////var index, cellNum: integer;BEGIN UpdateButtons(); ClearMatrix(); enable(page * (COL_COUNT + 1)); if (preset div BUTTON_COUNT) = page then // if the preset is on the current page.... BEGIN index:= preset mod BUTTON_COUNT; // raw preset index cellNum:= ((index mod ROW_COUNT) * (COL_COUNT + 1)) + 1 + (index div ROW_COUNT);// actual cell num enable(cellNum); END; END;PROCEDURE PresetChanged(); /////////////////////PRESET CHANGED////////////////var index, cellNum: integer;BEGIN page:= preset div BUTTON_COUNT; // figure out which page the preset is on // strace('page = ' + intToStr(page)); PageChanged(); setValue(presetOUT, preset);END;PROCEDURE Callback(n : Integer); ///////////////////////CALLBACK//////////////// VAR i, x, y, index, clicked, cellNum, column : Integer; BEGIN CASE n of presetsIN: BEGIN presets.setCommaText(GetStringValue(presetsIN)); presetCount:= presets.count; END; pagesIN: BEGIN pages.setCommaText(GetStringValue(pagesIN)); END; presetIN: BEGIN preset:= trunc(getValue(presetIN)); PresetChanged(); END; clickedIN: BEGIN cellNum:= trunc(getValue(clickedIN)); column := cellNum mod (COL_COUNT + 1); if (column = 0) then BEGIN // it's a page number page := cellNum div (COL_COUNT + 1); PageChanged(); END ELSE BEGIN index:= (column * ROW_COUNT) + (cellNum div (COL_COUNT + 1)) - ROW_COUNT;// + ROW_COUNT; preset:= (BUTTON_COUNT * page) + index; // compute preset number PresetChanged(); END; END; END; //case END; // Callback///////////////////////////////////////////////////////////////////////////////////////PROCEDURE Process;BEGINEND;Statistics: Posted by woodslanding — 10 Aug 2013, 07:57