SETFILTER - is not equal to (<>) not working NAV 90 - microsoft-dynamics-nav

I have been trying to make use of setfilter but it seems not working
FOR i := 1 TO ARRAYLEN(ItemGroupFilter) DO BEGIN
IF i <> ARRAYLEN(ItemGroupFilter) THEN BEGIN
IF ItemGroupFilter[i] <> '' THEN
IF ItemGroupString = '' THEN
ItemGroupString := '<>' + ('%' + FORMAT(i))
ELSE
ItemGroupString := ItemGroupString + ('|%' + FORMAT(i))
ELSE
ItemGroupString := ItemGroupString;
END ELSE BEGIN
IF ItemGroupFilter[i] <> '' THEN
IF ItemGroupString = '' THEN
ItemGroupString := '<>' + ('%' + FORMAT(i))
ELSE
ItemGroupString := ItemGroupString + ('|%' + FORMAT(i))
ELSE
ItemGroupString := ItemGroupString;
END;
END;
Item.RESET;
Item.SETFILTER("Item Group",ItemGroupString,ItemGroupFilter[1],ItemGroupFilter[2],ItemGroupFilter[3],ItemGroupFilter[4]);
As a result, only the first ItemGroupFilter[1] is doing the job. as from the OR (|) afterwards, it doesnt work
Message Values:
ItemGroupString = '<>%1|%2|%3|%4'
ItemGroupFilter[1] = '1'
ItemGroupFilter[2] = '2'
ItemGroupFilter[3] = '3'
ItemGroupFilter[4] = '4'

Found the solution. SETFILTER for <> should be as follows:
SETFILTER('<>%1&<>%2&<>%3&<>%4','1','2','3','4')
So my above ItemGroupString Variable consist of
ItemGroupString = '<>%1&<>%2&<>%3&<>%4'
Happy programming! :)

Related

Insert a line to a text file/template in Inno Setup before a specific line if doesn't exist yet

How can I add a line to a file/template before a specific other line, if it doesn't exist?
For example for the following JS file, I have to make sure that there's dependencies.push(...) line between the ABOVE THIS LINE and BELOW THIS LINE comment-lines. If the dependencies.push(...) is not present, I have to add it before the BELOW THIS LINE comment-line:
(function(ng) {
var dependencies = [];
/*DO NOT MODIFY ABOVE THIS LINE!*/
dependencies.push("mxdfNewTransaction.controller.mxdfNewTransactionCtrl");
/*DO NOT MODIFY BELOW THIS LINE!*/
ng.module('prismApp.customizations', dependencies, null);
})(angular);
I have to also do the same thing with a similar HTML template file.
Thanks for your help.
You have to parse the file line-by-line to find the spot to insert your code.
Something like this:
function AddLineToTemplate(
FileName: string; StartLine, EndLine, AddLine: string): Boolean;
var
Lines: TArrayOfString;
Count, I, I2: Integer;
Line: string;
State: Integer;
begin
Result := True;
if not LoadStringsFromFile(FileName, Lines) then
begin
Log(Format('Error reading %s', [FileName]));
Result := False;
end
else
begin
State := 0;
Count := GetArrayLength(Lines);
for I := 0 to Count - 1 do
begin
Line := Trim(Lines[I]);
if (CompareText(Line, StartLine) = 0) then
begin
State := 1;
Log(Format('Start line found at %d', [I]));
end
else
if (State = 1) and (CompareText(Line, AddLine) = 0) then
begin
Log(Format('Line already present at %d', [I]));
State := 2;
break;
end
else
if (State = 1) and (CompareText(Line, EndLine) = 0) then
begin
Log(Format('End line found at %d, inserting', [I]));
SetArrayLength(Lines, Count + 1);
for I2 := Count - 1 downto I do
Lines[I2 + 1] := Lines[I2];
Lines[I] := AddLine;
State := 2;
if not SaveStringsToFile(FileName, Lines, False) then
begin
Log(Format('Error writing %s', [FileName]));
Result := False;
end
else
begin
Log(Format('Modifications saved to %s', [FileName]));
end;
break;
end;
end;
if Result and (State <> 2) then
begin
Log(Format('Spot to insert line was not found in %s', [FileName]));
Result := False;
end;
end;
end;
You can use it like this:
if AddLineToTemplate(
'C:\path\to\customizations.js',
'/*DO NOT MODIFY ABOVE THIS LINE!*/',
'/*DO NOT MODIFY BELOW THIS LINE!*/',
' dependencies.push("mxdfNewTransaction.controller.mxdfNewTransactionCtrl");') then
begin
Log('Success');
end
else
begin
Log('Failure');
end;
Beware of the LoadStringsFromFile and SaveStringsToFile limitations, when working with Unicode files. See Inno Setup Reading file in Ansi and Unicode encoding.

TextFile ReWrite error in Lazarus

I have two files - one contains a number of short strings (that I call Items) and the other contains the IDs for these short strings. I also have a number of other files, each of which contains a very long string that is broken up into thousands of smaller strings by means of line breaks. I need to find the number of times each short string ("Item") occurs in each of the large string files, as well as the starting and ending position for each hit.
My first task is to remove the line breaks in the large files so that the hits do not straddle across two or more smaller strings, and then find the number of occurrences and start and end positions of each short string in the large strings, and report these results using the ID numbers for each short string.
I am getting a EInOutError (Access Denied) error apparently at the ReWrite(ResultFile) line (in the bottom half of the second procedure in the code below). Not sure why. I can see the file created for the results of the first long string, but it is blank. Here is the code; pretty simple and straightforward, actually. Thanks.
procedure TForm1.OpenStrCmdBtnClick(Sender: TObject);
begin
if OpenDialog1.execute then OpenStrEditBx.Text := OpenDialog1.FileName
else ShowMessage('Cannot open file!');
end;
procedure TForm1.FindItemfCmdBtnClick(Sender: TObject);
var
I, LenItem, NumTimes, offset: integer;
Extension, FileName, Dir, Str, Item, ID: string;
TempList, IDList, ItemList: TStringList;
searchResult: TSearchRec;
ResultFile: TextFile;
begin
IDList := TStringList.Create;
ItemList := TStringList.Create;
IDList.LoadFromFile('D:\...\IDs.txt');
ItemList.LoadFromFile('D:\...\Items.txt');
try
Dir := ExtractFilePath(OpenStrEditBx.Text);
//concatenate each line in each str sequence to get full string
if FindFirst(Dir + '*.txt', faAnyFile, searchResult) = 0 then
repeat
Extension := ExtractFileExt(OpenStrEditBx.Text);
FileName := StringReplace(searchResult.Name, Extension, '', [rFReplaceAll, rFIgnoreCase]);//remove file extension to get only file name
TempList := TStringList.Create;
TempList.LoadFromFile(Dir + searchResult.Name);
Str := '';
for I := 1 to TempList.Count-1 do // I <> 0 to ignore ID in first line
begin
Str := Str + TempList[I];
ProgressBar1.Position := (ProgressBar1.Position + 10) mod ProgressBar1.Max;
end;
TempList.Free;
//Find number and location of occurrences of each Item
for I := 0 to ItemList.Count-1 do
begin
Item := ItemList[I];
LenItem := Length(Item);
ID := IDList[I];
NumTimes := 0;
Offset := PosEx(Item, Str, 1);
AssignFile(ResultFile, 'D:\...\' + FileName + '.txt');
ReWrite(ResultFile);
while Offset <> 0 do
begin
inc(NumTimes);
if NumTimes > 0 then
WriteLn(ResultFile, 'The ' + IntToStr(NumTimes) + 'th occurrence of ' + 'ID# ' + ID + ' is from Position# ' + IntToStr(Offset) + ' to Position# ' + IntToStr(Offset + LenItem- 1) + ' in ' + FileName);
Offset := PosEx(Item, Str, Offset + LenItem);
end;
WriteLn(ResultFile, 'ID# ' + ID + ' occurs ' + IntToStr(NumTimes) + ' number of times in ' + FileName);
end;
CloseFile(ResultFile);
ShowMessage(FileName + ' done!');
until FindNext(searchResult) <> 0;
FindClose(searchResult);
finally
IDList.Free;
ItemList.Free;
end;
end;

Issue setting caller ID in a TSP

I have developed a TSP to talk to a CTI server. In the most part it works, but when setting the caller/called ID parties, in
function TSPI_lineGetCallInfo(
hdCall : HDRVCALL;
lpCallInfo : LPLINECALLINFO
) : LONG;
I am finding the offsets are all corrects but the size fields are NOT. At the end of the function I output (to debugger) the size and offsets of each field and they are what I expect them to be. But when I inspect the values using a TAPI program the sizes are different, (but the offsets are EXACTLY the same as per the debug statements) in fact the size field 5 regardless of what is actually there, whereas the debug statements at the end of the code below shows the correct values...
Any help greatly appreciated.
lpCallInfo^.dwCallerIDOffset := 0;
lpCallInfo^.dwCallerIDSize := 0;
lpCallInfo^.dwCalledIDOffset := 0;
lpCallInfo^.dwCalledIDSize := 0;
lpCallInfo^.dwConnectedIDOffset := 0;
lpCallInfo^.dwConnectedIDSize := 0;
extnid := thiscall.CallItem.ExtnId;
phoneno := thiscall.CallItem.DialNum;
extnid_size := (Length(extnid) + 1) * sizeof(WCHAR);
phoneno_size := (Length(phoneno) + 1) * sizeof(WCHAR);
extnidw := StringToWideStringEx(extnid, CP_ACP);
phonenow := StringToWideStringEx(phoneno, CP_ACP);
if lpCallInfo^.dwOrigin = LINECALLORIGIN_INTERNAL then
begin
{me}
lpCallInfo^.dwCallerIDOffset := sizeof(TLINECALLINFO);
lpCallInfo^.dwCallerIDSize := extnid_size;
Move(ExtnIdw[1], ptr^, extnid_size * 2);
ptr := Pointer(integer(ptr) + lpCallInfo^.dwCallerIDSize);
{other party}
if phoneno <> '' then
begin
lpCallInfo^.dwCalledIDOffset :=
sizeof(TLINECALLINFO) + lpCallInfo^.dwCallerIDSize;
lpCallInfo^.dwCalledIDSize := phoneno_size;
Move(phonenow[1], ptr^, phoneno_size * 2);
end;
end
else
begin
if thiscall.CallItem.CallType = 1 then
begin {incoming call}
{agent is the called party}
lpCallInfo^.dwCalledIDOffset := sizeof(TLINECALLINFO);
lpCallInfo^.dwCalledIDSize := extnid_size;
Move(ExtnIdw[1], ptr^, extnid_size);
ptr := Pointer(integer(ptr) + lpCallInfo^.dwCalledIDSize);
{other party is the caller}
if phoneno <> '' then
begin
lpCallInfo^.dwCallerIDOffset :=
sizeof(TLINECALLINFO) + lpCallInfo^.dwCalledIDSize;
lpCallInfo^.dwCallerIDSize := phoneno_size;
Move(phonenow[1], ptr^, phoneno_size);
ptr := Pointer(integer(ptr) + lpCallInfo^.dwCallerIDSize);
end;
end
else
begin
{agnet is the caller}
lpCallInfo^.dwCallerIDOffset := sizeof(TLINECALLINFO);
lpCallInfo^.dwCallerIDSize := extnid_size;
Move(ExtnIdw[1], ptr^, extnid_size);
ptr := Pointer(integer(ptr) + lpCallInfo^.dwCallerIDSize);
{dialed number is the called party}
if phoneno <> '' then
begin
lpCallInfo^.dwCalledIDOffset :=
sizeof(TLINECALLINFO) + lpCallInfo^.dwCallerIDSize;
lpCallInfo^.dwCalledIDSize := phoneno_size;
Move(phonenow[1], ptr^, phoneno_size);
ptr := Pointer(integer(ptr) + lpCallInfo^.dwCalledIDSize);
end;
end;
if (thiscall.CallItem.CallState = cs_Connected) and
(phoneno <> '') then
begin
lpCallInfo^.dwConnectedIDOffset := sizeof(TLINECALLINFO) +
lpCallInfo^.dwCallerIDSize + lpCallInfo^.dwCalledIDSize;
lpCallInfo^.dwConnectedIDSize := phoneno_size;
Move(phonenow[1], ptr^, phoneno_size);
ptr := Pointer(integer(ptr) + lpCallInfo^.dwConnectedIDSize);
end;
end;
end;
DEBUG('TSPI_lineGetCallInfo::dwCallerIDOffset=' + intToStr(lpCallInfo^.dwCallerIDOffset));
DEBUG('TSPI_lineGetCallInfo::dwCallerIDSize=' + intToStr(lpCallInfo^.dwCallerIDSize));
DEBUG('TSPI_lineGetCallInfo::dwCalledIDOffset=' + intToStr(lpCallInfo^.dwCalledIDOffset));
DEBUG('TSPI_lineGetCallInfo::dwCalledIDSize=' + intToStr(lpCallInfo^.dwCalledIDSize));
DEBUG('TSPI_lineGetCallInfo::dwConnectedIDOffset=' + intToStr(lpCallInfo^.dwConnectedIDOffset));
DEBUG('TSPI_lineGetCallInfo::dwConnectedIDSize=' + intToStr(lpCallInfo^.dwConnectedIDSize));
These are strange results. Your code seems to check out. It may be a longshot but the result could be caused by too few memory reserved for the lpCallInfo structure. What tapi program do you use? Most programs just reserve a large surplus beforehand. However, another commonly used approach is to 'ask' the TSP the exact amount needed by first calling TSPI_lineGetCallInfo and then reserving the exact amount after you set the dwNeededSize and returning LINEERR_STRUCTURETOOSMALL. You don't seem to check the dwTotalSize or set the dwNeededSize and dwUsedSize fields (which is dangerous).
Please look at the : LINEERR constants
and let me know if it solves the issue. If it doesn't, I would be curious to see the structure log from the Tapi Browser, but let's hope it works. Good luck!

Get currently-running MLM name in Arden

How do I get the currently-running MLM name without the user name at the beginning? The special keyword THIS_MLM_NAME returns the name of the MLM in the format USERNAME-302364198::MLM_NAME_HERE, but I just want the MLM's name by itself.
I tried using SUBSTRING:
SUBSTRING 200 CHARACTERS
STARTING AT ((FIND "::" IN THIS_MLM_NAME) + 2)
FROM THIS_MLM_NAME;
But this just returns null. What am I doing wrong?
The problem is that THIS_MLM_NAME is not actually an Arden string. If you test THIS_MLM_NAME IS STRING you will get false. To fix that, convert it to a string with THIS_MLM_NAME AS STRING:
ThisMLMName := SUBSTRING 200 CHARACTERS
STARTING AT ((FIND "::" IN STRING (THIS_MLM_NAME AS String)) + 2)
FROM (THIS_MLM_NAME AS String);
Since there is no debugger in Sunrise Acute Care's implementation of Arden, I wrote the following MLM to help show information about variables (name the module MOD_VARIABLE_INFO or change the code to match the actual name):
// data slot
(Variable, Padding) := ARGUMENT;
Result := "";
IF NOT EXIST Padding THEN
Padding := "";
ENDIF;
CR := (13 FORMATTED WITH "%c") || Padding;
Delimiter := "";
MOD_VARIABLE_INFO := MLM 'MOD_VARIABLE_INFO';
IF Variable IS LIST THEN
Result := Result || "List(" || (COUNT Variable) || ") [" || CR || " ";
FOR Item IN Variable DO
Result := Result || Delimiter;
TempResult := CALL MOD_VARIABLE_INFO WITH Item, Padding || " ";
Result := Result || TempResult;
Delimiter := "," || CR || " ";
ENDDO;
Result := Result || CR || "]";
ELSEIF Variable IS STRING THEN
Result := Result || "String";
ELSEIF Variable IS NUMBER THEN
Result := Result || "Number";
ELSEIF Variable IS BOOLEAN THEN
Result := Result || "Boolean";
ELSEIF Variable IS NET_OBJECT THEN
Result := Result || ".Net Object";
ELSEIF Variable IS NULL THEN
Result := Result || "Null";
ELSEIF Variable IS OBJECT THEN
Result := Result || "Object {" || CR || " ";
FOR Attr IN (EXTRACT ATTRIBUTE NAMES Variable) DO
Result := Result || Delimiter || Attr || ": ";
Item := ATTRIBUTE Attr FROM Variable;
TempResult := CALL MOD_VARIABLE_INFO WITH Item, Padding || " ";
Result := Result || TempResult;
Delimiter := "," || CR || " ";
ENDDO;
Result := Result || CR || "}";
ELSE
Result := Result || "Unknown (" || Variable || ")";
ENDIF;
// logic slot
CONCLUDE True;
// action slot
RETURN Result;
While this MLM returns "Unknown" for THIS_MLM_NAME, it at least shows that it is not any of the native Arden data types nor is it a .Net data type.
In the Sunrise MLM Editor, you can see what is going on in the underlying Lisp by syntax checking the MLM, then clicking on the "Syntax Check MLM" tab, selecting "Function Definition" then looking at the code in the lower right pane. Search for THIS_MLM_NAME and you will find (SETQ THIS_MLM_NAME 'USERNAME-302364198::MLM_NAME). From this you can see that the variable has been set to a plain quoted/unevaluated lisp expression rather than a string, which would look like (SETQ THIS_MLM_NAME "USERNAME-302364198::MLM_NAME").

What's wrong with this Pascal syntax?

I can't understand what's going on here. Can you give me a hand? This is the problematic code:
While not EOF(Archi) do begin
index:= index + 1;
Read(Archi, Alumno[index]);
Promes[index] := (Alumno[index].nota1 + Alumno[index].nota2) / 2;
if Promes[index] >= 6 then begin
alguPromo := true;
PromosIndex := PromosIndex + 1;
Promos[PromosIndex]:= Alumno[index];
end;
else begin
if Promes[index] > 4 then cantiRecu:= cantiRecu + 1;
else begin
LibresIndex += 1;
Libres[LibresIndex] := Alumno[index];
end;
end;
end;
The compiler marks error in the line 10 of this code (else begin). The error is:
Fatal: Syntax error, ; expected but ELSE found.
If someone wants to tray compile here is the entire code: http://pastebin.com/dRg1Lguu
Note that in Pascal the semicolon is a separator, not a terminator. Sometimes this doesn't matter, but in some cases it does, particularly before an else. Your code should be:
while not EOF(Archi) do
begin
index:= index + 1;
Read(Archi, Alumno[index]);
Promes[index] := (Alumno[index].nota1 + Alumno[index].nota2) / 2;
if Promes[index] >= 6 then
begin
alguPromo := true;
PromosIndex := PromosIndex + 1;
Promos[PromosIndex] := Alumno[index]
end
else
begin
if Promes[index] > 4 then
cantiRecu:= cantiRecu + 1
else
begin
LibresIndex := LibresIndex + 1;
Libres[LibresIndex] := Alumno[index]
end
end
end
Note that I have re-formatted the code into a more conventional style which helps to make the program logic more easily understood and which also makes it more obvious where the semicolons are needed and where they are not.
Looks like problem in += operator

Resources