John Gr Posted July 24, 2004 Share Posted July 24, 2004 Could some please post an example script using Resourse Strings. GetResourceString(VAR theString:STRING; id, index: INTEGER); John Greaney Quote Link to comment
Juno Posted July 30, 2004 Share Posted July 30, 2004 John: I'm not very familiar with resource files. However, I was able to create a STR# resource file named "test.rsrc" using resedit, which I saved to the plug-ins folder. The resource ID for my file was 128 and the following code displayed an alert dialog containing the first string in the string resource list. PROCEDURE restrng; VAR dialogok:BOOLEAN; textitem:STRING; BEGIN dialogok:=SetVSResourceFile('test'); GetResourceString(textitem,128,1); AlrtDialog(textitem); END; Run(restrng); HTH, -juno Quote Link to comment
Guest Posted July 30, 2004 Share Posted July 30, 2004 If you put your strings into a resource file then they can be translated to other languages by localizing distributors or users. The strings can be translated even if the script has been locked (encrypted). Basically you need two functions, one to open your resource file and one to read a string from it. Call SetVSResourceFile to open your resource file. Then call GetResourceString and provide the resource id of a STR# resource and the index of a particular string within that string list resource. Below is an example script that uses a resource file that contains two string list resources. One contains all the strings for use by a dialog, like the OK button and other labels. The other resource contains miscellaneous strings that may be displayed to the user in other ways ( like AlrtDialog). If the script cannot find the resource file or cannot find a string, it falls back on hardcoded strings. You may or may not want this type of setup. code: Procedure LocalTest; const kMyDialogStrings = 11000; { res id of 'STR#' resource with dialog strings } kOKItem = 1; { string index = item number of dialog control } kCancelItem = 2; kListBrowserItem = 4; kTitleIndex = 5; kMyMiscStrings = 11001; { res id of 'STR#' resource with misc strings } kHelloString = 1; { string index } kTestString = 2; var resFileOpen : BOOLEAN; promptString : STRING; {----------------------------------------} function OpenMyResourceFile :BOOLEAN; const kMyResourceFilename = 'MyTestResources'; BEGIN IF SetVSResourceFile(kMyResourceFilename) THEN OpenMyResourceFile := TRUE ELSE Begin Message('The resource file ', kMyResourceFilename, ' was not found.'); OpenMyResourceFile := FALSE; End; END; {----------------------------------------} FUNCTION GetLocalDialogString(strIndex :INTEGER) :STRING; VAR theString : STRING; BEGIN { Attempt to get strings from the resource file. } { Localizing distributors can translate strings within the resource file. } if (resFileOpen = true) then GetResourceString(theString, kMyDialogStrings, strIndex); { If localized string not found, use english. } if (theString = '') then CASE strIndex OF kOKItem: theString := 'OK'; kCancelItem: theString := 'Cancel'; kListBrowserItem: theString := 'Description'; kTitleIndex: theString := 'LB Test'; END; GetLocalDialogString := theString; END; {----------------------------------------} FUNCTION GetLocalMiscString(strIndex :INTEGER) :STRING; VAR theString : STRING; BEGIN { Attempt to get strings from the resource file. } { Localizing distributors can translate strings within the resource file. } if (resFileOpen = true) then GetResourceString(theString, kMyMiscStrings, strIndex); { If localized string not found, use english. } if (theString = '') then CASE strIndex OF kHelloString: theString := 'Hello World!'; kTestString: theString := 'This string is hardcoded in the script.'; END; GetLocalMiscString := theString; END; BEGIN resFileOpen := OpenMyResourceFile; promptString := GetLocalMiscString(kTestString); AlrtDialog(promptString); END; Run(LocalTest);[/code] Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.