Creating an array with variables - delphi

I am relatively new to Delphi so please bear with me. Basically, I need to set variables as different values based on whether or not I am testing in an English or French translated environment. All menus in these TC scripts are accessed by their names and in French they are not the same. I can, however, access them by their position in the menu - such as [4|2].
I have a list of constants and would like to set up an array to set MenuItem1 to either File|New or [4|2] depending on the value of tcDecimalSeparator <> '.' (set as a declared constant).
Does this make sense? What would be the easiest / best way to do this?
I know I could probably set this all up with data driven testing but I don't want to rework the scripts that much prior to release.

No, your proposed solution does not make sense. First, switching based on the current decimal separator is unreliable. Second, if you already know the positions of the menu items, and they always work, regardless of the program's language, then why mess around with the English menu captions at all? Just use the menu positions all the time. (Or, if you already have something set up to select the menu text based on the language, why not also use the French menu text instead of switching between English text and French positions?)
To do what you propose, you can set up a two-dimensional array of menu identifiers:
const
TLanguage = (lEnglish, lFrench);
TUIElement = (uiFileNew, uiFileOpen, ...);
MenuIDs = array[TUIElement] of array[TLanguage] of string = (
('File|New', '[4|2]'),
('File|Open', '[4|3]')
);
Then, when you want a string, select the item that corresponds to your UI element, and then select the string for the current language:
if tcDecimalSeparator = '.' then
CurrentLang := lEnglish
else
CurrentLang := lFrench;
UseMenuItem(MenuIDs[uiFileNew, CurrentLang]);

Related

How do i remove rows based on comma-separated list of values in a Power BI parameter in Power Query?

I have a list of data with a title column (among many other columns) and I have a Power BI parameter that has, for example, a value of "a,b,c". What I want to do is loop through the parameter's values and remove any rows that begin with those characters.
For example:
Title
a
b
c
d
Should become
Title
d
This comma separated list could have one value or it could have twenty. I know that I can turn the parameter into a list by using
parameterList = Text.Split(<parameter-name>,",")
but then I am unsure how to continue to use that to filter on. For one value I would just use
#"Filtered Rows" = Table.SelectRows(#"Table", each Text.StartsWith([key], <value-to-filter-on>))
but that only allows one value.
EDIT: I may have worded my original question poorly. The comma separated values in the parameterList can be any number of characters (e.g.: a,abcd,foo,bar) and I want to see if the value in [key] starts with that string of characters.
Try using List.Contains to check whether the starting character is in the parameter list.
each List.Contains(parameterList, Text.Start([key], 1)
Edit: Since you've changed the requirement, try this:
Table.SelectRows(
#"Table",
(C) => not List.AnyTrue(
List.Transform(
parameterList,
each Text.StartsWith(C[key], _)
)
)
)
For each row, this transforms the parameterList into a list of true/false values by checking if the current key starts with each text string in the list. If any are true, then List.AnyTrue returns true and we choose not to select that row.
Since you want to filter out all the values from the parameter, you can use something like:
= Table.SelectRows(#"Changed Type", each List.Contains(Parameter1,Text.Start([Title],1))=false)
Another way to do this would be to create a custom column in the table, which has the first character of title:
= Table.AddColumn(#"Changed Type", "FirstChar", each Text.Start([Title],1))
and then use this field in the filter step:
= Table.SelectRows(#"Added Custom", each List.Contains(Parameter1,[FirstChar])=false)
I tested this with a small sample set and it seems to be running fine. You can test both and see if it helps with the performance. If you are still facing performance issues, it would probably be easier if you can share the pbix file.
This seems to work fairly well:
= List.Select(Source[Title], each Text.Contains(Parameter1,Text.Start(_,1))=false)
Replace Source with the name of your table and Parameter1 with the name of your Parameter.

Teradata:Get a specific part of a large variable text field

My first Post: (be kind )
PROBLEM: I need to extract the View Name from a Text field that contains a full SQL Statements so I can link the field a different data source. There are two text strings that always exist on both sides of the target view. I was hoping to use these as identifying "anchors" along with a substring to bring in the View Name text from between them.
EXAMPLE:
from v_mktg_dm.**VIEWNAME** as lead_sql
(UPPER CASE/BOLD is what I want to extract)
I tried using
SELECT
SUBSTR(SQL_FIELD,INSTR(SQL_FIELD,'FROM V_MKTG_TRM_DM.',19),20) AS PARSED_FIELD
FROM DATABASE.SQL_STORAGE_DATA
But am not getting good results -
Any help is appreciated
You can apply a Regular Expression:
RegExp_Substr_gpl(SQL_FIELD, '(v_mktg_dm\.)(.*?)( AS lead_sql)',1,1,'i',2)
This looks for the string between 'v_mktg_dm.' and ' AS lead_sql'.
RegExp_Substr_gpl is an undocumented variation of RegExp_Substr which simplifies the syntax for ignoring parts of the match

how can I add text after an id in a word template with delphi?

I have a "template", a regular word file, and I need to insert text in specific places. I adapted the code from here:
http://www.swissdelphicenter.ch/torry/showcode.php?id=1304
to fit my needs. So I put some identifiers in the word file and used the replace function. It works fine but i can't do that to insert the text of a memo cause it's too big for the word replace function...
In short, i need a way to find an id (#social) and replace that with a large text... I've seen the range function but dont understand how it works. I need an example to get an idea of how to do it, please.
A better way to do Word templates is to insert bookmarks wherever information needs to be added programmatically. In the Word template, simply highlight the range you wish to turn into a bookmark and either use Insert -> Bookmark or press Ctrl+Shift+F5.
Give the bookmark a name and then insert your text like:
var
LWordDoc : WordDocument;
R : WordRange;
// ...open the document, etc
if LWordDoc.Bookmarks.Exists('My Bookmark') then begin
R := LWordDoc.Bookmarks.Item('My Bookmark').Range;
R.InsertAfter('foo');
end else begin
// handle missinng bookmark
end;
Here, using .InsertAfter the text will be added after the bookmark. You can also use any other Range methods or properties, for example R.Text := 'foo'; to substitute the highlighted range with the text you supply.
It is useful to store your bookmark names in some sort of intelligent structure - how you decide to do that is up to you.

Informix 4GL after field

Hi I want to add an after field logic, I have 4 check boxes (check1, check2, check3 and check4). When I put a check mark on either check2, check3 and check4, I want to put check mark on check1 automatically. Any idea. Thank you.
The weakness with AFTER FIELD is that it requires you to leave the field before it is triggered.
With Genero, when we added the ON CHANGE syntax many years ago, it was implemented such that if the widget was a GUI widget such as CHECKBOX, RADIOGROUP, COMBOBOX, the ON CHANGE would be triggered when the change was made, not when the focus left the field.
We also added the UNBUFFERED input mode so that your code didn't need all those DISPLAY's scattered throughout.
You didn't state the Informix 4gl version you were using, but if you were using Four Js Genero or IBM Informix Genero (and as you said checkbox then you might be) then the answer could be ...
INPUT ... ATTRIBUTES(UNBUFFERED)
...
ON CHANGE check2
LET rec.check1 = "Y"
ON CHANGE check3
LET rec.check1 = "Y"
ON CHANGE check4
LET rec.check1 = "Y"
AFTER FIELD check2
LET rec.check1 = 'Y'
DISPLAY rec.check1 TO check1
Rinse and repeat. I'm assuming the input variables are in a record rec with names check1 through check4. The key is the double operation of assignment and display; you need both AFAICR or it doesn't 'work'. I could use DISPLAY BY NAME rec.check1 here, but I don't usually use DISPLAY BY NAME; I would probably include the screen record in the DISPLAY too. Under reasonable assumptions, though, what I wrote will probably work.

Detecting regional settings (List Separator) from web

After having the unpleasant surprise that Comma Seperated Value (CSV) files are not necessarily comma-separated, I'm trying to find out if there is any way to detect what the regional settings list separator value is on the client machine from http request.
Scenario is as follows: A user can download some data in CSV format from web site (RoR, if it matters). That CSV file is generated on the fly, sent to the user, and most of the time double-clicked and opened in MS Excel on Windows machine at the destination. Now, if the user has ',' set as the list separator, the data is properly arranged in columns, but if any other separator (';' is widely used here) is set, it all just gets thrown into a single column. So, is there any way to detect what separator is used on the client machine, and generate the file accordingly?
I have a sinking feeling that it is not, but I'd like to be sure before I pass the 'can't be done, sorry' line to the customer :)
Here's a JavaScript solution that I just wrote based on the method shown here:
function getListSeparator() {
var list = ['a', 'b'], str;
if (list.toLocaleString) {
str = list.toLocaleString();
if (str.indexOf(';') > 0 && str.indexOf(',') == -1) {
return ';';
}
}
return ',';
}
The key is in the toLocaleString() method that uses the system list separator.
You could use JavaScript to get the list separator and set it in a cookie which you could then detect from your server.
I checked all the Windows Locales, and it seems that the default list separator is virtually always either ',' or ';'. For some locales the drop-down list in the Control Panel offers both options; for others it offers just ','. One locale, Divehi, has a strange character that I've not seen before as the list separator, and, for any locale, it is possible for the user to enter any string they want as the list separator.
Putting random strings as the separator in a CSV file sounds like trouble to me, so my function above will only return either a ';' or a '.', and it will only return a ';' if it can't find a ',' in the Array.toLocaleString string. I'm not entirely sure about whether array.toLocaleString has a format that's guaranteed across browsers, hence the indexOf checks rather than picking out a character at a specific index.
Using Array.toLocaleString to get the list separator works on IE6, IE7, and IE8, but unfortunately it doesn't seem to work on Firefox, Safari, Opera, and Chrome (or at least the versions of those browsers on my computer): they all seem to separate array items with a comma, irrespective of the Windows "list separator" setting.
Also worth noting that by default Excel seems to use the system "decimal separator" when it's parsing numbers out of CSV files. Yuk. So, if you're localizing the list separator you might want to localize the decimal separator too.
I think everyone should use Calc from OpenOffice - it asks when you open a file about encoding, column separators and other. I don't know answer for your question, but maybe you can try to send data in html tables or in xml - excel should read both of them correctly. From my experience it isn't easy to export data to excel. Few weeks ago I have problem with it and after few hours of work I asked a person, who couldn't open my csv file in excel, about version. It was Excel 98...
Take a look on html example and xml.
The simplier version of getListSeparator function, enabling any character to be a separator:
function getListSeparator_bis()
{
var list = ['a', 'b'];
return(list.toLocaleString().charAt(1));
}// getListSeparator_bis
Just set any char (f.e. '#') as list separator in your OS and try the code as above. The appropriate char (i.e. '#' if set as sugested) is returned.
Could you just have the users with non comma separators set a profile kind of option and then generate CSVs based on user settings with the default being commas?
Toms, as far as I'm aware there is no way of achieving what you're after. The most you can do is try and detect the user locale and map it against a database of locales/list separators, altering the list separator in the .CSV file as a result.

Resources